Home > Database > Mysql Tutorial > body text

The whole process of environment deployment of MySQL and Django under Ubuntu14.04

黄舟
Release: 2017-03-29 13:36:12
Original
1094 people have browsed it

This article mainly introduces Django and MySQL# under Ubuntu 14.04 ##The whole process of environment deployment is introduced in detail through the step-by-step Installation steps. I believe it has certain reference value for everyone. Friends in need can take a look below.

Brief steps. (Ubuntu14.04)

  • #Python

    Installation

    ## Django
  • Mysql installation and configuration
  • Record my deployment process, it is also convenient for some children in need, please don’t criticize~

1. Python environment setup

Operating system Ubuntu14.04, comes with Python2.7.6

im@58user:/$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Copy after login

2. Django environment Build

##The current version of Django has reached 1.11. First go to the official website to download the Linux corresponding file, then unzip & install it (official website download address)

tar xzvf Django-1.11.x.tar.gz
cd Django-1.11.x
sudo python setup.py install
Copy after login

At this time. ImportError may be prompted:

No

module

named setuptools

<a href="http://www.php.cn/code/8212.html" target="_blank">Execute </a><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:bash;">sudo https://bootstrap.pypa.io/ez_setup.py -O - | sudo python</pre><div class="contentsignin">Copy after login</div></div> and then execute

python setyp.py install"
Copy after login

The Django installation is successful~ !

3. Mysql installation

Execute the command, you may need to enter the root password and confirm during operation

sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysqld-dev
Copy after login
Then connect to MySQL. 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
Copy after login

How to enter

mysql database

:

> * sudo mysql
* mysql -u root -p 
然后输入密码
Copy after login

4. Set the root password for mysql

##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&#39;) where User =&#39;root&#39;;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> exit
Copy after login
The 'root' in the brackets is the new password

5. Create a new project

Arrived It’s 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
Copy after login


* init.py: Python features , can be an empty file, indicating that this folder is a package that can be imported.

  1. * settings.py:

    Configuration file

    , this article mainly modifies database information and templates. Information about directories and loaded modules.
  2. * url.py: URL configuration file, specifying the mapping relationship between functions

    and URLs.
  3. * wsgi.py: will not be used in this article, nginx/apache+wsgi is used when running Django in a production environment

  4. Next Let's write a HelloWorld page.

  5. Create the 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
Copy after login

Write the following code in the views.py file

from django.http import HttpResponse

def hello(request):
return HttpResponse(“Hello World~!~!”)
Copy after login

Then add the path Add it to the urls.py file

from django.conf.urls import url
from django.contrib import admin
from views import hello

urlpatterns = [
url(r&#39;^admin/‘, admin.site.urls),
url(r&#39;^hello/‘, hello),
]
Copy after login

Then execute it in the Hello directory

python manage.py runserver 0.0.0.0:8080

Start the server
Open the browser and visit

127.0.0.1:8000/hello/

You can see the display results.

Summarize

The above is the detailed content of The whole process of environment deployment of MySQL and Django under Ubuntu14.04. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!