Pyhon + Django 1.7.2 tutorial + virtualenv for simple use, pyhondjango

Source: Internet
Author: User
Tags install django sqlite manager virtual environment virtualenv django tutorial

Pyhon + Django 1.7.2 tutorial + virtualenv for simple use, pyhondjango

I used python in my recent work. I have never been familiar with it before. After I put aside the syntax and features of python, I have been using django's official documents for a few days, the document is very detailed. My English level is like that, and there is almost no pressure on me. It is recommended that new users like me go directly to the official documentation. The content is definitely updated to the latest version, the content is organized in a gradual and orderly manner. Of course, even if you follow the document step by step, some problems will always occur during the process, here, the blog post authority will be able to repeat or have a deeper understanding after you write down a flow account. By the way, let's update it and look at some of your own ways of thinking, if it is possible to bring something to others by the way, it will be even more icing on the cake. Let's go back to the question:

    The content and character of the blog post are basically what I understand after learning. I don't like to be a document Porter of nature. The content may be watery, we hope that you can correct and understand the errors.

My python runtime environment is (windows 7 + python 2.7.9 + django 1.7.2)

    Django tutorial:

Django official tutorial document of the first seven parts (https://docs.djangoproject.com/en/1.7/intro/tutorial01/) basic content is to install django, create a project, django framework built-in admin management background, create your own app, write your own unit tests, compile a modular reusable app, package and install it, and go through some key parts here:

  • There is a relationship between creating a project and creating an app that contains supersets. An app can be seen as a reusable module, if it is out of the scope of django, it is similar to some modules that come with python.
  • After python is installed, the global environment variables of python have been set. packages such as pip and easy_install have been installed or set by default.
  • Sqlite is used by default in the project. If you want to view the db data in the project, you can download the Firefox extension of SQLite manager (Other
  • After models is changed in django 1.7.2, You need to manually add it to migrations and then execute the corresponding migrate command to make the change take effect. Under the root directory of the app, you can see the folder named migrations, which contains xxxx_initial.py for viewing. It is used to generate scripts for the corresponding db (ABSTRACT Non-SQL scripts for better understanding)
  • Django comes with a set of orm, which abstracts the logic for interacting with db, similar to the entity framework of. net. The combination of model + orm is similar to the [Model] role in mvc.
  • The methods in the view of django play the role of Controller in mvc, reading data, rendering pages, and may seem like the View in mvc for the first time]
  • The page template in django is similar to [View] in mvc, which contains some of its own syntax and mainly serves as a data placeholder, simple hybrid logic and so on (similar to razor of jade or asp.net mvc)
  • When you package and release your own polls app, polls will be installed in the global python execution environment (C: \ Python27 \ Lib \ site-packages) by default ), when testing your own package, you do not want to pollute the global environment. It is best to use pip + virtualenv
    Create your own isolated python execution environment (virtual, sandbox, or whatever)

    Installation and Setup of virtualenv:

    In windows, you only need to run "pip install virtualenv" to install virtualenv. After the installation is complete, it can be found in the global python environment.

In windows, we recommend that you compare the command line with the command line tool. We recommend a command line tool powercmd (paid software)

After finishing django tutorial, you should have a mysite project and a packaged polls package. Installing the polls package will pollute the global environment. We use virtualenv to create an isolated environment named myEnv, then run the created mysite project in myEnv and install the packaged polls to re-run the entire site.

    

Go to the directory where we created the virtual environment and activate the isolation environment (activating the isolation environment is actually setting the context of the command line execution environment). There is no relation to installing the django extension in the next step, run the pip script command directly from the cd to the scripts directory.

    

Install the polls package to the myEnv isolation environment, and run the mysite project in the isolation environment to view the running effect:

    

    

So far, the entire isolation environment with django1.7.2 is ready, and the polls package is manually installed, and the mysite project is successfully run. The first time I wrote a technical blog post, I was writing to death, writing to work overtime, mom! After creating a virtual isolation environment, you can imagine that you are tossing around in the python environment of the system. Whether you install django, You can package your own extensions, or any third-party package can be used. It provides a context for running your own project. It is as warm as Fan Ye's arms.

 

 

References:

Https://docs.djangoproject.com/en/1.7/intro/

Http://virtualenv.readthedocs.org/en/latest/userguide.html

Http://virtualenv-chinese-docs.readthedocs.org/en/latest/

 

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.