Just started to learn Django, using the Django Book 2.0 tutorial. I feel this tutorial is easier to get started than the official documentation, but since this tutorial is a little bit less for the version, I'm under the Django 1.8 version. So it's still a bit of a pit to watch and practice. Keep a record of the problems you've encountered.
First, activate the app
Under the MySite directory, create a new app.
$ python manage.py Startapp Books
In the setting.py, find Installed_apps, add the new App,books, as follows. "Django book2.0", is "mysite.books", in 1.8 this will error, cannot find the app
Installed_apps = (# ' django.contrib.admin ', # ' Django.contrib.auth ', # ' Django.contrib.contenttypes ', # ' Django.contr Ib.sessions ', # ' Django.contrib.messages ', # ' django.contrib.staticfiles ', ' books ',)
Ii. Building a model
1. After you finish editing models.py, verify that the model is accurate. You should use the Python manage.py check.
$ python manage.py validate/usr/local/lib/python2.7/distpackages/django-1.8.8-py2.7.egg/django/core/management/ Commands/validate.py:15:removedindjango19warning: "Validate" has
been deprecated in favor of "check". removedindjango19warning)
2. View model models.py How SQL will run in the database, use Python manage.py sqlall books will report the following error
Commanderror:app ' books ' has migrations. Only the sqlmigrate and Sqlflush commands can is used when a app has migrations.
The right approach is
$ python manage.py makemigrations booksmigrations for ' books ': 0001_initial.py:-Create model author-create model book -Create model Publisher-add field Publisher to book$ python manage.py sqlmigrate books 0001BEGIN; CREATE TABLE ' Books_author ' (' id ' integer auto_increment NOT null PRIMARY KEY, ' name ' varchar = NOT null, ' email ' varcha R (254) not NULL), ... $ python manage.py migrateoperations to perform:apply all migrations:booksrunning migrations:rend Ering model states ... Done Applying books.0001_initial ... Ok
Some of the problems with Django first