python -m django --version
gunicorn mysite.wsgi:application
daphene mysite.asgi:application
django-admin startproject mysite .
python manage.py runserver
python manage.py startapp polls
cd app
python ../manage.py startapp sub_app
python manage.py shell
python manage.py shell_plus
python manage.py collectstatic -c
python manage.py createsuperuser
http://localhost:8000/admin
python manage.py test <app_name>
python manage.py test polls
python -Wd manage.py test (This will show all deprecation warnings)
python -c "import django; print(django.__path__)"
from polls.models import Question, Choice
Question.objects.all()
Q = Question(question_text="What's new?", pub_date=timezone.now())
Q.save()
Q.id
Q.question_text
Q.pub_date
Q.question_text="What's up?"
Q.save()
Question.objects.all()
Question.objects.filter(id=1)
Question.objects.filter(question_text__startswith='What')
Current_year = timezone.now().year
Question.objects.get(pub_date__year=current_year)
Q = Question.objects.get(pk=1)
Q.choice_set.all()
Q.choice_set.create(choice_text='Not much', votes=0)
Q.question
Q.choice_set.count()
def __str__(self):
return self.question_text
python manage.py shell
from django.contrib.auth.models import User
user = User.objects.all()[0]
user.set_password('new_password')
user.save()
[django]
check
compilemessages
collectstatic
collectstatic --noinput -c (Generate static files to serve)
createcachetable
dbshell
diffsettings
dumpdata
python manage.py dumpdata > dumpdata.sql
flush
findstatic
inspectdb
loaddata
loaddata initial_data (Searches for and loads the contents of the named fixture into the database)
makemessages
makemigrations (creating new migrations)
migrate (applying and unapplying migrations)
migrate home_device zero (Uninstall migrations from an application)
The migrate command takes all the migrations that haven’t been applied (Django tracks which ones are applied using a special table in your database called django_migrations) and runs them against your database - essentially, synchronizing the changes you made to your models with the schema in the database.
Migrations are very powerful and let you change your models over time, as you develop your project, without the need to delete your database or tables and make new ones - it specializes in upgrading your database live, without losing data.
runserver
sendtestemail
shell
showmigrations (lists a project’s migrations and their status)
sqlflush
sqlmigrate (displays the SQL statements for a migration)
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver