Django Study Notes (1) -- install, create a project, and configure

Source: Internet
Author: User

Django Study Notes for crazy summer vacation (1)


The Django book

Video: csvt Django video


1. Create a project


Django-Admin. py startproject mysite.


2. Run the Development Server


Python manage. py runserver


3. File structure


Mysite/

── Manage. py

── Mysite

── _ Init _. py

── Settings. py

── URLs. py

── Wsgi. py


Mange. py: a command line tool that allows you to interact with this Django project in multiple ways. Type python manage. py help to view help and specify the configuration file setting. py.

The mysite folder in the mysite folder is a python package _ init _. py. The package must wait for the file, and its content is empty.

Setting. py project configuration file. For example, root_urlconf = 'mysite. urls' configures the URL file location.

URLs. py URL configuration file



4. View and URL Configuration


Create a view. py file in the mysite folder under mysite (the name can be any one)


Input


 from django.http import HttpResponse def output(request,str):     html = "


Add (R' ^ input/(\ W +) ', output) in URLs. py ),

from django.conf.urls import patterns, include, url from django.contrib import adminfrom mysite.view import outputadmin.autodiscover()urlpatterns = patterns('',    # Examples:    # url(r'^$', 'mysite.views.home', name='home'),    # url(r'^blog/', include('blog.urls')),    url(r'^admin/', include(admin.site.urls)),    (r'^input/(\w+)',output), )


Then Python manage. py runserver runs the Development Server

Enter http: // 127.0.0.1: 8000/input/hello in the browser, and you will be able to see wellcom in Hello input http: // 127.0.0.1: 8000/input/Wellcome.


5. Now let's talk about what they are doing.


View. py defines a method. The first parameter must be the httprequest variable, followed by the variable passed by URLs. Returns an httpresponse object.


Usrls. py is a URL configuration file that defines what address will be followed when you enter in your browser.

(R' ^ input/(\ W +) ', output) tuples. The first one is a regular expression (Python Regular Expression Introduction ). Http://blog.csdn.net/billvsme/article/details/23520007), represents the variable enclosed in parentheses, to be passed to the subsequent function; the second is the function to be responded, to add from mysite. View import output to tell the location of Python output.



















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.