I've started to work with Django when I first encountered with World Wide Web (WWW) for writing a web application for Sharif Energy Water Nexus Event, which is available here. Since then, I use Go more than Python, so I need to refresh my memory and also celebrate my great memories with Mohammad Mahboubi and Navid Mashayekhi.
You need first create your Django project:
pipx run --spec django==4.2.5 django-admin startproject django101and then you can create applications:
python manage.py startapp blogPlease note that you need to write down the applications in /django101/settings.py
under the variable named INSTALLED_APPS.
This application is very simple so it uses SQLite.
pipenv install
pipenv shellpython manage.py migrate
python manage.py runserverFor working with database you can use litecli which is available as a development package.
python manage.py createsuperuserHaving a good language server is an awesome experience that every developer wants. Pyright seems a good choice to me and for having it work with Django, you can:
pipenv install --dev 'django-stubs[compatible-mypy]'And then you must register it to mypy by add the following into mypy.ini:
[mypy]
plugins =
mypy_django_plugin.main
[mypy.plugins.django-stubs]
django_settings_module = "django101.settings"Maybe you want to use django-rest-framework too for having an awesome ReST API.
pipenv install --dev 'djangorestframework-stubs[compatible-mypy]'[mypy]
plugins =
mypy_django_plugin.main, mypy_drf_plugin.mainFor running Django on production it is better to use gunicorn.
gunicorn django101.wsgi --log-file -