https://github.com/codegeek004/django
https://github.com/codegeek004/django
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/codegeek004/django
- Owner: codegeek004
- Created: 2024-11-07T02:17:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-24T11:03:07.000Z (over 1 year ago)
- Last Synced: 2025-01-09T08:12:37.552Z (over 1 year ago)
- Language: Python
- Size: 57.5 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Django Tutorial
This is a django application developed from the official documentation's tutorial. This will explain you the flow of django framework.
To start with we have to create a virtual environment for django and access it.
python3 -m venv django-env
source django-env/bin/activate
After creating the virtual environment you need to install django
pip install django
Now you need to bootstrap a django project using the following command
django-admin startproject mysite django_tutorial
Now your directory looks something like this:
django_tutorial/
manage.py
mysite/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
In this the manage.py file is used to run the django application(s). The mysite directory is the project. Using this project directory you an create multiple applications.
DEBUG=True We can turn on or off the debug mode using this. DEBUG should be set to false when application is in productionALLOWED_HOSTS['*'] Using this we can specify what are the host/domain names your application could serve. This prevents HTTPS host head attacksINSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls', # Your app
]INSTALLED_APPS contains django's built in apps and custom apps you have created.
DATABASES contains configurations for connecting to your database.After successfully creating the project you need to make applications. For creating the applications you need to create an app in the same directory.
python manage.py startapp poll
This will create a app directory poll which is laid out something like this.
polls/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
views.py
In views.py file you define the views for your application. Views handle the logic behind what data is displayed and how it is presented to the user.
To run your application run the command
python manage.py runserver. If you have any changes in your database run the commands
python manage.py makemigrations
python manage.py migrate
# django