How to build a Django application using python

Source: Internet
Author: User
This article mainly describes how to build a Django application using python. recently, it also solves version conflict errors. First, make sure that python is installed on your machine. second, make sure that you have installed Django on it.
The next step is to build the first Django application.
A simple operation is to enter the code on a windows Terminal:

The code is as follows:


1 django-admin.py startproject mysite


You can, for example, create a project in the E: \ Python33 \ python_workspace directory of my computer.
You set the directory.
Run the following command:

The code is as follows:


Django-admin.py startproject mysite

# Create an application named after mysite



Next, go to the E: \ Python33 \ python_workspace \ mysite directory.
Note: you must first go to the mysite Directory. Otherwise, it will fail !!!!
Run the code:

The code is as follows:


Python manage. py runserver 8080

# It means to start the service. The port is 8080. If no port is set, the default value is 80000.

For example:

After starting the service, we can now access it through a browser.
Enter http: // localhost: 8080 in the address bar of the browser.

By now, your first django application has been successful !!!

Problems and Solutions:
1. importError: No module named django. core
Analysis and solution: this is the problem encountered when running the command: django-admin.py startproject mysite, you can be sure that in
Django has been successfully installed on your machine. you can run the following command:

The code is as follows:


Python-c "import django; print (django. get_version ())"

Secondly, the django-admin.py has been added to the environment variables:

The code is as follows:


# Add to path environment variable # django installation directory
E: \ Python33 \ Lib \ site-packages \ django \ bin

I did the above two steps, but still encountered an error. later I found the cause of the problem: I installed many python versions on my computer: python2.7.5, python32, python33
Finally, we uninstalled python2.7.5 and python32, leaving only python33, and then run it again !!!
2. python: can't open file 'manage. py'
This is similar to the above reason. the solution is also a version conflict. uninstall the other, leaving only python33. SUCCESS !!!

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.