Basic
init project
-
install anaconda
-
install django:
conda install django -
install django plugin in PyCharm
preferences -> Project -> Python Interpreter
use anaconda to create a project env, and install django plugin
-
create project:
django-admin startproject myProject, thencd myProject -
create database (par defalut: sqllite):
python ./manage.py migrate -
create superuser:
python ./manage.py createsuperuser -
run dev server:
python ./manage.py runserver
create App and Model
-
create App in Project:
python ./manage.py startapp myAppA django project can have multiple Apps. All the Apps need to be registered in
setting.pyof the project.INSTALLED_APPS = [ # other APPS 'myApp' ] -
create Model
Model is a class. It is used to create the table in database.
Optional: In order to see the model in admin page, we need to register it into
admin.pyof App.# myApp/admin.py from myApp.models import myModel admin.site.register(myModel) -
make migration:
python manage.py makemigrations -
migrate:
python manage.py migrate