====== Django ======
===== Commands to manage the project =====
To know the version:
python -m django --version
Create a Django project:
django-admin startproject mysite .
Launch project:
manage.py runserver
Create app:
python manage.py startapp polls
Create app in a different folder than root which should exist:
python manage.py startapp coopolis apps/coopolis
Create migration files and prepare DB:
python manage.py makemigrations
python manage.py migrate
:?: squashmigrations
Open the Django shell:
python manage.py shell
If you prefer to use another interpret (in the next case ipython should be installed into the environment):
python manage.py shell -i ipython
===== Minimum Django =====
* From: [[https://github.com/syntarsus/minimal-django|Minimal Django repo]]
import sys
from django.conf import settings
from django.conf.urls import url
from django.core.management import execute_from_command_line
from django.http import HttpResponse
settings.configure(
DEBUG=True,
ROOT_URLCONF=sys.modules[__name__],
)
def index(request):
return HttpResponse('A minimal Django response!
')
urlpatterns = [
url(r'^$', index),
]
if __name__ == '__main__':
execute_from_command_line(sys.argv)
===== Sections =====
[[wiki2:python:django:apps]]
[[wiki2:python:django:urls]]
[[wiki2:python:django:views]]
[[wiki2:python:django:models]]
[[wiki2:python:django:forms]]
[[wiki2:python:django:auth]]
[[wiki2:python:django:templates]]
[[wiki2:python:django:admin]]
[[wiki2:python:django:tests]]
[[wiki2:python:django:sites]]
===== Other =====
[[wiki2:python:django:others]]
[[wiki2:python:medium_django]]
[[wiki2:python:notes#asyncio_on_django|asyncio and Django]]
[[wiki2:python:django:project]]
===== Libraries =====
* [[https://django-constance.readthedocs.io/en/latest/|Constance: Dynamic settings (on DB)]]
* [[https://github.com/idlesign/django-etc|Utils that are not on the basic framework]]
* [[https://github.com/lazybird/django-solo|Django-Solo: To create singletones on the DB]]
* [[https://django-tables2.readthedocs.io/en/latest/|Create tables]]
* [[https://github.com/jazzband/django-widget-tweaks|Allow to add properties to the html rendered components]] also [[https://simpleisbetterthancomplex.com/tutorial/2018/11/28/advanced-form-rendering-with-django-crispy-forms.html|Crispy forms]].
* [[http://whitenoise.evans.io/en/stable/index.html|WhiteNoise: Para que sea Django en producción quien sirva los estáticos sin necesidad de nginx]].
===== Links =====
* [[https://djangosnippets.org/|Django Snippets]]