The first time you write a static web page on Django

Source: Internet
Author: User
Tags django website

Create a new Python Django project:

Win+r Enter the cmd command interface and CD to the specified project directory, such as my project directory is E:\wamp\Apache24\www\

Input e: Jump e-Drive

Enter CD wamp\apache24\ jump to the specified directory

input django-admin.py startproject www Establish Python Django Engineering, a folder, WWW, is generated with the following structure:
www/
manage.py
www/
__init.py
settings.py
urls.py
wsgi.py

which
manage.py: A command-line tool through which you can invoke the Django shell and database. Type the Python manage.py-h to see its related features.
__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: Default settings for the project, including database information, debug flags, and other work variables.
The URL setting for the Urls.py:django project. As a directory of your Django website, it is responsible for mapping the URL pattern to the application.
wsgi.py: A simple and common interface between a server gateway interface (Python Web server, Gateway Interface), a Web server and a Web service program, or a framework.

Enter CD www into www directory, where you can enter python manage.py runserver run the server, after successful startup, enter http://127.0.0.1:8000/ on the Internet Explorer URL to test, and press Ctrl+break on the keyboard to exit the server

Create a new Python Django project:

input django-admin.py Startapp Firstapp Create the Firstapp project and generate a name for the Firstapp folder, which is structured as

firstapp/
__init__.py

admin.py

models.py

tests.py

views.py
Migrations/
__init.py
notes, If you have ever published the Hello World page, but have not used the web frame, simply enter Hello World in the hello.html text file and upload it to a Web server, such as http://127.0.0.1/ helloworld.html.

then you should know . Python Django Two aspects:

The first is that the content of the page is implemented by View function.

Second, URL defined in the URLCONF configuration information of the urls.py file.

Open www/www/settings.py File modification Installed_apps, add the name of the Firstapp project we created in the last line  , modified as follows:
Installed_apps = (
' Django.contrib.admin ',
' Django.contrib.auth ',
' Django.contrib.contenttypes ',
' Django.contrib.sessions ',
' Django.contrib.messages ',
' Django.contrib.staticfiles ',

' Firstapp ',
)

remark, what is this step? If you don't add the new app to Install_apps, Django can't automatically find the app template file ( files under app-name/templates/) and Static Files ( files in app-name/static/), and you will learn what they are used for respectively.

Create a new static Web page test:

and then in Firstapp folder, create a Templates folder under the Templates folder and create a new file named home.html with the encoding format set to Utf-8, which is written in the file:

<! DOCTYPE html>

<title> Welcome to </title>

<body>

Welcome to the self-improvement Academy

</body>

Open www/www/ under the urls.py file, directly modify the contents of the file:

Include, URL
Admin

Urlpatterns = [
URL (
R ' ^$'firstapp.views.home 'name= ' Home ' ),
# URL (R ' ^blog/', include (' Blog.urls ')),

URL (R ' ^admin/', include (Admin.site.urls)),
]

input python manage.py runserver run the server, after successful startup, enter http://127.0.0.1:8000/on the Internet Explorer URL and see on the Web page Welcome to the self-improvement academy

remark: Recommended Learning website: http://www.ziqiangxuetang.com/django/django-tutorial.html

The first time you write a static web page on Django

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.