Write the first Django app, part one--Create a project

Source: Internet
Author: User

Write the first Django app, part one--Create a project

Let's learn by example.

Through this guided tour, we will teach you step-by-step to create a simple voting system.

The system is divided into two parts:

1. A public page that allows people to vote and view the results of a poll.

2. An admin page lets you add, modify, and delete votes.

We assume that you have the Django installed. You can run the Python compiler and enter the import Django to test that Django is installed. If the command runs successfully, there is no error, which means that Django is already installed.

New Project

If you are using Django for the first time, you must make sure that some initialization is complete. That is, you need to automatically generate some code to create a Django project-a series of Django Setup instances, including database configuration, Django-specific options, and program-specific settings.

Using the command line, the CD enters the folder where you want to save your code, and runs the command django-admin.py startproject MySite. It creates a MySite folder in the current folder.

If you are installing Django via Python setup.py, django-admin.py will be in your system path.

If it's not in your path, you can find it in Site-packages/django/bin, Site-packages is your Python installation directory.

(I don't quite understand the above, I copy the django-admin.py to the folder where the code is stored, and then run the command django-admin.py startproject MySite to create the project).

Let's take a look at what Startproject has generated:

mysite/

__init__.py

manage.py

settings.py

urls.py

These files are:

1.__init__.py: An empty file that tells Python to think of this folder as a Python package. (If you're a beginner, read the official Python documentation to learn more about the package.) )

2.manage.py: A practical command line that lets us interact with Django projects in a variety of ways.

3.settings.py: Set/Configure Django Project

The URL mapping for the 4.urls.py:django project.

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.