Skip to content

Latest commit

 

History

History
91 lines (63 loc) · 2.74 KB

README.md

File metadata and controls

91 lines (63 loc) · 2.74 KB

Let's Learn Django

Django makes it easier to build better web apps more quickly and with less code

GitHub Workflow Status GitHub Pipenv locked Python version GitHub

Introduction

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.

Where did it start?

You need first create your Django project:

pipx run --spec django==4.2.5 django-admin startproject django101

and then you can create applications:

python manage.py startapp blog

Please note that you need to write down the applications in /django101/settings.py under the variable named INSTALLED_APPS.

How to run?

This application is very simple so it uses SQLite.

pipenv install
pipenv shell
python manage.py migrate
python manage.py runserver

For working with database you can use litecli which is available as a development package.

python manage.py createsuperuser

Better development experience

Having 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.main

On Production 🚀

For running Django on production it is better to use gunicorn.

gunicorn django101.wsgi --log-file -