While working with Django you use a lot of commands. I decided to create a list of commands for myself to make my development a little faster.
Quick links to tutorials:
- 1 – Working with models
- 2 – Creating admin panel
- 3 – Creating views and using templates
- 4 – Creating forms
- 5 – Testing
- 6 – Customizing apps look and feel
- Creating reusable apps
My project folder is this: ~/Documents/common-app-server/app_server
My project name is: tokens
Creating virtual environment:
1 |
$ virtualenv env |
Activating virtual environment:
1 |
$ source env/bin/activate |
Installing Django on virtual environment:
1 |
$ pip install Django |
Django version:
1 |
$ python -c "import django; print(django.get_version())" |
Starting a project:
1 |
$ django-admin.py startproject tutorial |
Creating Django application:
1 |
(env)~/Documents/common-app-server/app_server: $ ./manage.py startapp multiverse |
Syncing database for the first time:
1 |
python manage.py syncdb |
Creating migrations:
1 |
$ ./manage.py makemigrations tokens |
Looking at migrations:
1 |
$ ./manage.py sqlmigrate tokens 0001 |
Starting migrations:
1 |
$ ./manage.py migrate |
Entering sqlite mode:
1 |
(env)~/Documents/common-app-server/app_server: $ ./manage.py dbshell |
Recreating database:
1. Delete migrations folder
2. Use this command to clear database:
1 |
$ ./manage.py sqlclear tokens| ./manage.py dbshell |
3. Create and run migrations
Running a local server:
1 |
$ ./manage.py runserver |
Creating admin user:
1 |
$ ./manage.py createsuperuser |
App view:
1 |
http://localhost:8000/tokens/ |
Admin view:
1 |
http://localhost:8000/admin/ |
Installing DjangoRestFramework:
1 |
$pip install djangorestframework |