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 !!!