Some of the questions that Django used first

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.