The first time I wrote a static webpage on Django, django wrote a static webpage.

Source: Internet
Author: User
Tags django website

The first time I wrote a static webpage on Django, django wrote a static webpage.

Create a Python Django project:

Win + RGo to the cmd command interface and cd it to the specified project directory. For example, my project directory is E: \ wamp \ Apache24 \ www \

Input E: Jump to the edisk

Enter cd wamp \ Apache24 \ to jump to the specified directory

InputDjango-admin.py startproject wwwCreatePython DjangoProject,A www folder is generated with the following structure:
Www/
Manage. py
Www/
_ Init. py
Settings. py
Urls. py
Wsgi. py

Where:
Manage. py: a command line tool that can call Django shell and database. Type python manage. py-h to view its functions.
_ Init _. py: Let Python treat this directory as a file required by an Development Kit (that is, a group of modules. This is an empty file. You do not need to modify it.
Settings. py: the default settings of the project, including the database information, debugging flag, and other working variables.
Urls. py: Set the URL of the django project. It can be viewed as the directory of your django website and is responsible for ing the URL mode to the application.
Wsgi. py: A simple and common Interface between a Web Server and a web service program or framework.

Enter cd www to enter the www directory. You can enterPython manage. py runserverRun the server. After the server is started successfully, enter http: // 127.0.0.1: 8000/on the Internet Explorer URL for the test. Press ctrl + break on the keyboard to exit the server.

Create a Python Django project:

InputDjango-admin.py startapp firstappCreate a firstapp project and generate a folder named firstapp. Its structure is

Firstapp/
_ Init _. py

Admin. py

Models. py

Tests. py

Views. py
Migrations/
_ Init. py
Remarks,If you have published a Hello World page, but you have never used a Web page 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.

So you should understandPython DjangoThere are two aspects:

First, the page content is implemented by view function;

SecondURLDefined in the URLconf configuration information of the urls. py file.

 
Open the www/settings. py file and modifyINSTALLED_APPS, Add the createdFirstappProject name, which is modified as follows:
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'firstapp',
)

What is this step? If the newly created app is not added to INSTALL_APPS, django cannot automatically findTemplate File(App-name/templates/Files) andStatic files(App-name/static/Files), you will learn what they are used.

Create a static Web page test:

ThenFirstappCreate a templatesfolder under the folder, and create a new file named home.html under the folder. The encoding format is UTF-8, which is written into the file:

<! DOCTYPE html>

<Html>

<Head>

<Title>Welcome </title>

</Head>

<Body>

Welcome to self-improvement school

</Body>

</Html>

Open www/ To directly modify the file content:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(
r'^$', 'firstapp.views.home', name='home'),
   
# url(r'^blog/', include('blog.urls')),

   
url(r'^admin/', include(admin.site.urls)),
]

InputPython manage. py runserverRun the server. After the server is started, enter http: // 127.0.0.1: 8000/on the Internet Explorer URL.Welcome to self-improvement school

Note: Recommended Learning Website: Http://www.ziqiangxuetang.com/django/django-tutorial.html

Related Article

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.