Django's first project helloword

Source: Internet
Author: User
Tags install django

1. Install Python

Python installation is not introduced here.

2. Install Django

1) You can download Django from the official website. Here, we provide an installation method suitable for various platforms (provided that you have installed the GIT version controller)

2) for Windows, you need to download git from the Internet.

3) Ubuntu users can: $ sudo apt-Get install Git-core

4) after installing git, clone it from GitHub.

 
$ Git clone https://Github.com/django/django

5) switch to the directory

 
$ CD Django

6) Installation

 
$ Python setup. py install

7) test whether Django is successfully installed.

 
$ Python#Enter the python Environment$ImportDjangoPrintDjango. Version

3. Start Hello World

1) Select a directory to store the Django project and switch to the directory.

 
$ Sudo mkdir djangoworkspace $ CD djangoworkspace

2) create a project myblog

 
$ Django-admin.py startproject myblog

After the creation is successful, a mange. py and myblog folder will be generated under the myblog file. The directory structure is as follows:

 
Myblog-Myblog-_ Init _. py-Settings. py-URLs. py-Wsgi. py-Manage. py

If you are prompted that the django-admin.py command cannot be found, you needAdd% Python PATH %/scripts to environment variable path.

3) start the project

 
Python manage. py runserver

After it is started, open http: // 127.0.0.1: 8000/in the browser. If "It Works" appears, instead of 404 not found, it indicates that the startup is successful.

The default IP address set by runserver is 127.0.0.1 and the port is 8000. You can also specify an IP address, as shown in figure

 
Python manage. py runserver168.23.1.54 8080

4) customize your Hello world and create a new view. py file in the myblog module folder (including the _ init _. py folder ).

 
FromDjango. HTTPImportHttpresponseDefMyhelloworld (request ):ReturnHttprespnse ("Hello my Django!")

5) configure the URL path and change URLs. py to the following:

 From Django. conf. URLs Import  Patterns, include, URL  From Myblog. Views Import  Myhelloworld  From Django. contrib Import  Adminadmin. autodiscover () urlpatterns = Patterns ( ''  ,  #  Examples:     #  URL (R' ^ $ ', 'myblog. Views. home', name = 'home '),      #  URL (R' ^ blog/', include ('blog. urls ')), URL (R '  ^ Hello/$  '  , Myhelloworld)  #  URL (r '^ admin/', include (Admin. Site. URLs )), )

Enter http: // 127.0.0.1: 8000/Hello/in the browser. We can see that our Hello world is out.

If an error message is displayed for a large version, you may be prompted for the error.CodeThe spelling is wrong.

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.