Django
General
- Django is used to create static full stack server side website.
- Django rest framework is used to create apis
- Django makes use of the model, view, template design pattern.
- You can use shortcuts from django.shortcuts to cut down on code that gets repeated across multiple projects.
- You can use generic views to replace writing out views in full by hand.
Creating Django projects
-
Create the project directory
-
Create a virtual environment to isolate our package dependencies locally
-
Install Django and Django REST framework into the virtual environment
-
Set up a new project with a single application
Making model changes
- Change your models (in models.py).
python manage.py makemigrationsto create migrations for those changespython manage.py migrateto apply those changes to the database.
Runserver
python manage.py runserver
Admin
-
python manage.py createsuperuserto create admin account -
Add models to admin panel by using
admin.site.register: ```py title=polls/admin.py from django.contrib import admin from .models import Choice, Question
admin.site.register(Question) admin.site.register(Choice) ```