Operating system Ubuntu14.04, comes with Python2.7.6
im@58user:/$ python
Python 2.7.6(default, Oct 262016,20:30:19)[GCC 4.8.4] on linux2
Type "help","copyright","credits" or "license"for more information.>>>
The current version of Django has reached 1.11. Go to the official website to download the file corresponding to Linux, then unzip & install. (Official website download address)
tar xzvf Django-1.11.x.tar.gz
cd Django-1.11.x
sudo python setup.py install
At this time, it may prompt ImportError: No module named setuptools
Execute sudo https://bootstrap.pypa.io/ez_setup.py -O-| sudo python
Then execute sudo python setyp.py install
So far, Django is installed successfully~!
Execute the following command, you may need to enter the root password and confirm it during operation.
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysqld-dev
Then link MySQL and Python
sudo apt-get install python-dev
sudo wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip
unzip MySQL-python-1.2.5.zip
cd MySQL-python-1.2.5/
sudo python setup.py install
The way to enter the mysql database:
First enter mysql in the first way
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-A
Database changed
mysql> update user set Password =PASSWORD('root') where User ='root';
Query OK,3 rows affected(0.00 sec)
Rows matched:3 Changed:3 Warnings:0
mysql> exit
In brackets'root'Is the new password
Time to verify the results
Switch the current directory to Python's Worspace, and enter the new project name:
im@58user:~/PythonProjects$django-admin.py startproject Hello
im@58user:~/PythonProjects$ cd Hello/
im@58user:~/PythonProjects/Hello$ tree
├── Hello
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
Next we write a HelloWorld page.
Create a views.py file in the first level directory under the Hello file
im@58user:~/PythonProjects/Hello$ touch views.py
im@58user:~/PythonProjects/Hello$ ls
Hello manage.py views.py
im@58user:~/PythonProjects/Hello$ tree
.
├── Hello
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
└── views.py
1 directory,6 files
Write the following code in the views.py file
from django.http import HttpResponse
def hello(request):returnHttpResponse("Hello World~!~!")
Then add the path to the urls.py file
from django.conf.urls import url
from django.contrib import admin
from views import hello
urlpatterns =[url(r'^admin/', admin.site.urls),url(r'^hello/', hello),]
Then execute in the Hello directory```python manage.py runserver 0.0.0.0:8080
Open the browser and visit http://127.0.0.1:8000/hello/ to see the display results.
![ Hello world](http://upload-images.jianshu.io/upload_images/1319879-a19f1df512b51616.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
To read more articles of the author, you can check my [personal blog](http://dandanlove.com/) and public account:
![ Revitalization Book City](http://upload-images.jianshu.io/upload_images/1319879-612c4c66d40ce855.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Recommended Posts