Django (ii) the first Django app

Source: Internet
Author: User
Tags django server

The first Django app we're going to make a polling site.

He is made up of two parts:

    • A common interface allows users to vote
    • A management interface, to vote on the deletion.

First of all, you have to create a new project, just one line of code, and Django will automatically do the job for you.

Switch the CD to the path you want to store your project under, such as C: \, enter

django-admin.py Startproject MySite

At this point, your C: \ will have a more folder MySite, open you will see

mysite/ manage.py mysite/ __init__. py settings.py urls.py wsgi.py

The outermost mysite root directory is just the container for your entire project, and you can change its name at will without affecting the program.

manage.py: A command-line tool that allows you to interact with the Django project in a number of ways.

The following MySite directory is the project package you actually created, and you can import it in another program. Eg:mysite.urls

__init__.py: Let Python treat the directory as a required file for a development package (that is, a set of modules). This is an empty file, generally you do not need to modify it

settings.py: The setup or configuration of the Django project. View and understand the types of settings available in this file and their default values

The URL setting for the Urls.py:django project. Visualize it as the directory for your Django site

Wsgi.py:wsgi-compatible Web Server The entry point for services provided by your project

Below, let's start it. First switch to the outermost MySite directory and enter:

manage.py Runserver.

You will see the following text:

Validating models ...


0 errors found
January 15, 2015-15:50:53
Django version 1.5.12, using Settings ' mysite.settings '
Development server is running at http://127.0.0.1:8000/
Quit the server with Control-break.

This means that you have successfully started, login to: Http://127.0.0.1:8000/go down and have a look.

If this screen appears, it means OK.

By default, the port that Runserver starts is 8000, and if you want to modify it, you can enter:

manage.py runserver 8080

If you want to switch IP, please enter:

manage.py Runserver 0.0.0.0:8000

Note that each time you modify the code, the Django server will automatically reload without you having to restart each time. However, you need to restart manually when you add a new file, or if the compilation file does not restart automatically.

Below, for the configuration of the database, open the settings.py file, you will see such a piece of code:

Django (ii) the first Django app

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.