簡(jiǎn)要步驟。(Ubuntu14.04)
Python安裝 Django Mysql的安裝與配置記錄一下我的部署過(guò)程,也方便一些有需要的童鞋,大神勿噴~
一、Python環(huán)境搭建
操作系統(tǒng)Ubuntu14.04,自帶Python2.7.6
im@58user:/$ pythonPython 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>
二、Django環(huán)境搭建
目前Django的版本已經(jīng)到1.11了。先去官網(wǎng)下載Linux對(duì)應(yīng)的文件,然后解壓&安裝。(官網(wǎng)下載地址)
tar xzvf Django-1.11.x.tar.gzcd Django-1.11.xsudo python setup.py install
這時(shí)可能會(huì)提示ImportError: No module named setuptools
執(zhí)行
sudo https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
然后執(zhí)行
python setyp.py install```
到此Django安裝成功~!
三、Mysql安裝
執(zhí)行一下命令,運(yùn)行過(guò)程中可能需要輸入root密碼并進(jìn)行確認(rèn)。
sudo apt-get install mysql-server mysql-clientsudo apt-get install libmysqld-dev
然后鏈接MySQL和Python
sudo apt-get install python-devsudo wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zipunzip MySQL-python-1.2.5.zipcd MySQL-python-1.2.5/sudo python setup.py install
進(jìn)入mysql數(shù)據(jù)庫(kù)的方式:
> * sudo mysql* mysql -u root -p 然后輸入密碼
四、給mysql設(shè)置root密碼
先以第一種方式進(jìn)入mysql
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set Password = PASSWORD(‘root') where User ='root';Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> exit
括號(hào)里面的'root'就是新的密碼
五、新建項(xiàng)目
到了驗(yàn)證結(jié)果的時(shí)候了
將當(dāng)前目錄切換到Python的worspace下,輸入新建的項(xiàng)目名稱(chēng):
im@58user:~/PythonProjects$django-admin.py startproject Helloim@58user:~/PythonProjects$ cd Hello/im@58user:~/PythonProjects/Hello$ tree├── Hello│ ├── init.py│ ├── settings.py│ ├── urls.py│ └── wsgi.py└── manage.py* __init__.py:Python特性,可以是空文件,表明這個(gè)文件夾是一個(gè)可以導(dǎo)入的包。 * settings.py:配置文件,本文主要修改數(shù)據(jù)庫(kù)信息、模板目錄、加載模塊的信息。 * url.py:URL配置文件,指定函數(shù)與URL的映射關(guān)系。 * wsgi.py:本文中不會(huì)使用,nginx/apache+wsgi在生產(chǎn)環(huán)境中運(yùn)行Django時(shí)使用
接下來(lái)我們寫(xiě)一個(gè)HelloWorld頁(yè)面。
在Hello文件下的一級(jí)目錄創(chuàng)建views.py文件
im@58user:~/PythonProjects/Hello$ touch views.pyim@58user:~/PythonProjects/Hello$ lsHello manage.py views.pyim@58user:~/PythonProjects/Hello$ tree.├── Hello│ ├── init.py│ ├── settings.py│ ├── urls.py│ └── wsgi.py├── manage.py└── views.py1 directory, 6 files
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注