Python Web framework Analysis and Learning article _ Peng You

Source: Internet
Author: User
Tags install django

Analysis article:

Just to the internet to find a "talk about Python web framework," the system of analysis of five kinds of mainstream Python framework, now Python's mainstream framework has Django, PYLONS&TURBOGEARS&REPOSE.BFG, Tornado&web.py&bottle&flask and Quixote. It analyzes the pros and cons of these five frameworks from a macro perspective, and after reading we decided to choose Django because:

Django:

Overview: It is the largest of the Python framework, it is the most complete document, the market share the highest, the largest number of recruitment positions.

Advantages:

L Complete documentation, the official documents are very complete

L Full range of solutions

• Powerful URL routing configuration

L self-service management background

Disadvantages:

L system coupling is very high, do not facilitate the introduction of some external tools

L system comes with an ORM less powerful than SQLAlchemy

L template function is relatively weak

L URL needs to be manually configured

L AUTH module is too high in coupling with other modules

In short, Django is a great way to quickly develop some Web applications, and our project itself is not very complex, and there is no need to cite external library estimates, but there is one important reason for this is the highest Django penetration and the most complete documentation. Learn not to worry about finding a learning resource or a problem finding a solution, so we chose it.

Configuration article:

After deciding to use Django as our development framework for this project, I started learning about Django's configuration, and then I wrote a simple Hello World program with a tutorial on the web to get a sense of Django.

Installation:

I'm installing python-3.3.5:http://rj.baidu.com/soft/detail/17016.html?ald+django1.6.5 http://download.csdn.net/download/. henrygas2014/7720223

Pack python: Run Python-3.3.5.msi First, then install the prompts to mount Python, remembering your installation directory, such as D:\python. Then, in the environment variable, advanced system settings, properties, computer, and so on, locate the path variable, double-click it, and add the D:\python at the end.

Install Django: Unzip the downloaded compressed package, then go to the Django directory (that is, the directory with setup.py in it, I take D:\Django-1.6.5\Django-1.6.5\ for example), and then shift+ right-click "Open Command Window Here", And then enter

Python setup.py Install

Then it will be installed, this time there is a possibility that the version between Python and Django does not support each other, in this case, a different version of the line. After the installation is successful, enter Python to open the Python interpreter

>>> Import Django

>>> Django. VERSION

If the display (1,6,5, ' final ', 0) indicates the installation was successful.

Then follow the previous Python-like method to put the D:\Django-1.6.5\Django-1.6.5\django\bin (that is, the corresponding Django directory of \django\bin\), add to the environment variable.

Hello World article:

Note: This tutorial is suitable for versions after Django 1.4, see the old version: http://www.nowamagic.net/academy/detail/1318235

1. Create a new Django project: Open the command line in the directory where you want to create a new project, and enter

django-admin.py Startproject mysite1

Where Mysite1 is the project name

2. You can then go to the Mysite1 folder, open the command line in shift+ right-click in the current directory, and enter

Python manage.py runserver 0.0.0.0:80

After you see the following prompt

On behalf of Django has started, and then enter 127.0.0.1 in the browser can see this picture

Then create a new Views folder in the current directory and create a new two empty files __init__.py and first_fun.py under this Views folder. Then write first_fun.py

#! /usr/bin/env python
#coding =utf-8
From django.http import HttpResponse
def hello (Request):
Return HttpResponse ("Hello world!")

Change urls.py after

#! /usr/bin/env python
#coding =utf-8
From Django.conf.urls import patterns, include, url
#导入views
From Www.views.first_fun import Hello
# Uncomment the next lines to enable the admin:
# from Django.contrib Import admin
# Admin.autodiscover ()
Urlpatterns = Patterns ("',
URL (r ' ^hello/$ ', hello),
# Examples:
# URL (R ' ^$ ', ' www.views.home ', name= ' home '),
# URL (R ' ^www/', include (' Www.foo.urls ')),
# Uncomment the Admin/doc line below to enable admin documentation:
# URL (R ' ^admin/doc/', include (' Django.contrib.admindocs.urls ')),
# Uncomment the next line to enable the admin:
# URL (R ' ^admin/', include (Admin.site.urls)),
)

Then type directly into the browser:

http://127.0.0.1/hello/

You'll see the following interface.

Python Web framework Analysis and Learning article _ Peng You

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.