django-admin startproject <projectname>If you are in the directory django, run
django-admin startproject mysitewill create the following files:
django/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
Here,
manage.py: command-line utility that lets you interact with this Django project in various ways.mysite/: actual Python package for your project.mysite/__init__.py: empty file that makesmysite/a Python package.mysite/settings.py: settings/configuration for this Django project.mysite/urls.py: the URL declarations for this Django project; a "table of contents" of your Django-powered site.mysite/wsgi.py: an entry-point for WSGI-compatible web servers to serve your project.
python manage.py runserverIf you want to change the server's port, pass it as a command-line argument, e.g.:
python manage.py runserver 8080In the directory that contains manage.py, run
python manage.py startapp <appname>where appname is the name of the application you want to add. For example,
python manage.py startapp logswill create a directory logs in django with the following layout:
logs/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
python manage.py createsuperuserYou may need to supply an username, an email, and a password.
python manage.py makemigrations [<app_name>]creates new migrations based on the changes detected to your models.
python manage.py migratesynchronizes the database state with the current set of models and migrations.
Points:
- Steps of creating web pages with Django:
- define a URL for the page to be created;
- write a view funtion to retrieve and process the data needed for the page;
- write a template to build the page for the browser.
- Fields are specified by class attributes. They are the only required part of a model defining the database fields.
- Built-in field types: TODO:
- Any page that lets a user enter and submit information on a web page is a form.
- Superuser name:
DeepWalter - Password:
have fun