├── .deepsource.toml ├── .gitignore ├── CONTRIBUTING.md ├── HelloWorld_APP ├── README.md ├── helloapp │ ├── db.sqlite3 │ ├── helloapp │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ ├── howdy │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── templates │ │ │ ├── about.html │ │ │ └── index.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ └── manage.py └── requirements.txt ├── LICENSE ├── README.md ├── django_starter_app.md └── welcome_to_django.md /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "python" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | runtime_version = "3.x.x" 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # OS Files 10 | .DS_STORE 11 | *.zip 12 | 13 | # Distribution / packaging 14 | .Python 15 | env/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # Environments 32 | Learning-Django-Env/ 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *,cover 53 | .hypothesis/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local.py 62 | 63 | # Flask stuff: 64 | instance/ 65 | .webassets-cache 66 | 67 | # Scrapy stuff: 68 | .scrapy 69 | 70 | # Sphinx documentation 71 | docs/_build/ 72 | 73 | # PyBuilder 74 | target/ 75 | 76 | # IPython Notebook 77 | .ipynb_checkpoints 78 | 79 | #IDE 80 | .vscode/ 81 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Hello All, 2 | 3 | ## Feel free to add django code examples here. We are all learners,lets learn together. 4 | 5 | 6 | ### You may add code, documentation, improve formatting/structure etc. 7 | 8 | 9 | ## For Beginners: 10 | 11 | Instructions- 12 | 13 | 1. Fork this Repository (using the button at the top-right side) 14 | 2. Clone your forked repository to your desktop/laptop (i.e. `git clone `) 15 | 3. Create a new branch for your modifications (i.e. `git branch new-branch-name` and check it out `git checkout new-branch-name`) 16 | 4. Add your files (git add -A), commit (git commit -m "my first commit") and push (git push origin new-user) 17 | 5. Create a pull request (*You have raised your first PR!*) 18 | 6. Star this repository (optional) 19 | 20 | 21 | ## Thanks. 22 | -------------------------------------------------------------------------------- /HelloWorld_APP/README.md: -------------------------------------------------------------------------------- 1 | ## Getting started 2 | 3 | Clone the repository. 4 | 5 | ## Running the app 6 | 7 | Install all the requirements in your environment. 8 | 9 | `pip install -r requirements.txt` 10 | 11 | After that, run the app using Django manage.py. 12 | 13 | `python manage.py runserver` 14 | 15 | Access the homepage on `http://localhost:8000` 16 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animenon/Learning-Django/81621c1f4996b29ffcbae4afb6db6a70aef8f252/HelloWorld_APP/helloapp/db.sqlite3 -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/helloapp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animenon/Learning-Django/81621c1f4996b29ffcbae4afb6db6a70aef8f252/HelloWorld_APP/helloapp/helloapp/__init__.py -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/helloapp/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for helloapp project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.9.6. Upgraded to Django 3.0.4 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'qz%_ir)1khas+&5kdxs)09ie&=rg^87u$*g%$c&t_h7@oed)db' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'howdy' 41 | ] 42 | 43 | # Upgrade from MIDDLEWARE_CLASSES 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'helloapp.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'helloapp.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases 77 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators 89 | 90 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 91 | 92 | AUTH_PASSWORD_VALIDATORS = [ 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 101 | }, 102 | { 103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 104 | }, 105 | ] 106 | 107 | 108 | # Internationalization 109 | # https://docs.djangoproject.com/en/1.9/topics/i18n/ 110 | 111 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 112 | 113 | LANGUAGE_CODE = 'en-us' 114 | 115 | TIME_ZONE = 'UTC' 116 | 117 | USE_I18N = True 118 | 119 | USE_L10N = True 120 | 121 | USE_TZ = True 122 | 123 | 124 | # Static files (CSS, JavaScript, Images) 125 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ 126 | 127 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 128 | 129 | STATIC_URL = '/static/' 130 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/helloapp/urls.py: -------------------------------------------------------------------------------- 1 | """helloapp URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url, include 17 | from django.contrib import admin 18 | 19 | urlpatterns = [ 20 | url(r'^admin/', admin.site.urls), 21 | url(r'^', include('howdy.urls')), 22 | ] 23 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/helloapp/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for helloapp project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "helloapp.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animenon/Learning-Django/81621c1f4996b29ffcbae4afb6db6a70aef8f252/HelloWorld_APP/helloapp/howdy/__init__.py -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HowdyConfig(AppConfig): 5 | name = 'howdy' 6 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animenon/Learning-Django/81621c1f4996b29ffcbae4afb6db6a70aef8f252/HelloWorld_APP/helloapp/howdy/migrations/__init__.py -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/templates/about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Howdy! 6 | 7 | 8 |

Welcome to the About Me page

9 |

10 | This is 'about.html' page. 11 | This view is rendered on browser after adding it to urls.py file and configuring it on views.py file. 12 |

13 | Go back home 14 | 15 | 16 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Howdy! 6 | 7 | 8 |

Howdy! I am Learning Django!

9 | About Me 10 | 11 | 12 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from howdy import views 3 | 4 | 5 | urlpatterns = [ 6 | url(r'^$', views.HomePageView.as_view()), 7 | url(r'^about/$', views.AboutPageView.as_view()), 8 | ] 9 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/howdy/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.views.generic import TemplateView 3 | 4 | 5 | # Create your views here. 6 | class HomePageView(TemplateView): 7 | def get(self, request, **kwargs): 8 | return render(request, 'index.html', context=None) 9 | 10 | 11 | class AboutPageView(TemplateView): 12 | template_name = "about.html" 13 | -------------------------------------------------------------------------------- /HelloWorld_APP/helloapp/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "helloapp.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /HelloWorld_APP/requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.2.7 2 | Django==3.0.14 3 | pytz==2019.3 4 | sqlparse==0.3.1 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Learning-Django 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Learning-Django 2 | 3 | [![DeepSource](https://deepsource.io/gh/animenon/Learning-Django.svg/?label=active+issues&show_trend=true)](https://deepsource.io/gh/animenon/Learning-Django/?ref=repository-badge) [![DeepSource](https://deepsource.io/gh/animenon/Learning-Django.svg/?label=resolved+issues&show_trend=true)](https://deepsource.io/gh/animenon/Learning-Django/?ref=repository-badge) 4 | 5 | Introducing Django 6 | 7 | This is a short introduction to the Django framework. Django is a web development 8 | framework written in Python, and its aim is to be versatile. 9 | It's capable of building any application you might envision, but it's also 10 | performant and convenient. You'll build applications quickly, and they'll run quickly as well. 11 | Django is also a very complete framework. Out of the box, it contains everything you need 12 | to build any web application. 13 | 14 | It has its own HTML template language, a beautiful ORM framework for storing your data 15 | in a database, sessions, authentication, internationalization, etc. 16 | 17 | Now, what I want to focus on are the various components that make up a Django application. 18 | Mainly, the following three types of components: 19 | models, templates, and views. 20 | And these three types of components together make up the architecture that's central to Django, 21 | which is aptly called model template view, or MTV in short. 22 | 23 | Features of Django 24 | 25 | It is ridiculously fast. Django was designed to help developers take applications from concept to completion as quickly as possible. 26 | 27 | It is reassuringly secure. Django takes security seriously and helps developers avoid many common security mistakes. 28 | 29 | It is exceedingly scalable. Some of the busiest sites on the Web leverage Django’s ability to quickly and flexibly scale. 30 | 31 | It is incredibly versatile. Companies, organizations and governments have used Django to build all sorts of things — from content management systems to social networks to scientific computing platforms. 32 | 33 | 34 | 35 | Examples to Learn Python Django 36 | ------------------------------- 37 | 38 | 1. "Welcome to Django" example is like the "Hello World" example in Django. 39 | 40 | 2. "Django Starter App" expands upon the "Welcome to Django" example, this time, creating an MVC app. 41 | 42 | 3. "Introducing Django" gives an introduction to the Django language and briefly explains its features. 43 | 44 | Structure of a Django Project: 45 | ``` 46 | └── new_project 47 | ├── new_project 48 | │ ├── __init__.py 49 | │ ├── settings.py 50 | │ ├── urls.py 51 | │ └── wsgi.py 52 | └── manage.py 53 | ``` 54 | 55 | Source : https://www.djangoproject.com 56 | -------------------------------------------------------------------------------- /django_starter_app.md: -------------------------------------------------------------------------------- 1 | # Django Starter App, MVC 2 | Adapted from: https://docs.djangoproject.com/en/1.11/intro/tutorial01/ 3 | 4 | ## Starting the app 5 | 6 | Now that you have completed the "Welcome to Django" example, it's time to create your first app. 7 | 8 | From the command line, cd into `mysite` or whereever `manage.py` is. Then, run: 9 | 10 | ``` 11 | python manage.py startapp polls 12 | ``` 13 | 14 | This command starts a Django app called `polls`. You should thus see a directory called `polls` which should be laid out like this: 15 | 16 | ``` 17 | polls/ 18 | __init__.py 19 | admin.py 20 | apps.py 21 | migrations/ 22 | __init__.py 23 | models.py 24 | tests.py 25 | views.py 26 | ``` 27 | ## MVC framework 28 | 29 | Before getting started, let's briefly examine the directory structure. Don't worry too much about the rest of the app, but you'll notice two files `models.py` and `views.py`. 30 | 31 | Models and views are two parts of an MVC framework, or model-view-controller framework. If you've already worked with another MVC framework like Ruby on Rails or Node.js, you can skip this section. 32 | 33 | The MVC framework has three main parts, the **model**, the **view**, and the **controller**. 34 | 35 | ### Model 36 | 37 | The model is the core component of the MVC framework. If you've ever worked with OOP (object-oriented programming), the model is the component that most closely resembles an object. 38 | 39 | ### View 40 | 41 | The view is what the user sees on the website. Usually, this will render an HTML file, though for API-only applications, you may return JSON. 42 | 43 | ### Controller 44 | 45 | The controller controls user input, and uses that input to manipulate an instance of a model. 46 | 47 | [Wikipedia](https://en.wikipedia.org/wiki/Model–view–controller) has a good diagram of the MVC framework: 48 | 49 | ![MVC file](https://upload.wikimedia.org/wikipedia/commons/a/a0/MVC-Process.svg) 50 | 51 | ## Further steps 52 | 53 | To proceed further in the polls app, refer to the Django tutorial linked at the beginning of the page. 54 | -------------------------------------------------------------------------------- /welcome_to_django.md: -------------------------------------------------------------------------------- 1 | # Creating a project 2 | 3 | From the command line, cd into a directory where you’d like to store your code, then run the following command: 4 | 5 | ``` 6 | $ django-admin startproject mysite 7 | ``` 8 | 9 | `startproject` would create: 10 | 11 | ``` 12 | mysite/ 13 | manage.py 14 | mysite/ 15 | __init__.py 16 | settings.py 17 | urls.py 18 | wsgi.py 19 | ``` 20 | 21 | Change to the root directory and run: 22 | 23 | ``` 24 | $ python manage.py runserver 25 | ``` 26 | This will check the Django Project. By default, the `runserver` command starts the development server on the internal IP at port `8000`. Visit `http://127.0.0.1:8000/` on any Web browser and you will see a __“Welcome to Django”__ page. 27 | --------------------------------------------------------------------------------