您好,欢迎访问一九零五行业门户网

Getting Django Started on Windows 7 with Python 3 and MySQL_MySQL

pythondjango
bitscn.com07.03.2014|6 views|related microzone resourcesclustrix whitepapers
what we offer: clustrix features
infographic: the future of the database
proven in production: clustrix case studies
like this piece? share it with your friends:
|more
django is a python web framework library and it works on both python 2 or 3. i will show you how to get python 3 set up in cygwin environment.
if you're on a windows os, the best experience i have when working with django on windows is to use cygwin, a unix emulator shell that runs on windows. the pip and django commands would automatically setup in cygwin's path after installed. the default python package on cygwin is only 2.7 though, so you have to search for python3 package to get the latest python version. and you can have both versions installed without problem, but the executable are named python and python3 respectively.
1. install cygwin python3 package. verify python3 -v is working.
2. install pip by downloading this get-pip.py file fromhttp://pip.readthedocs.org/en/latest/installing.htmland then run python3 get-pip.py. verify pip3 --version is working.
(note: if you are running windows 7, you might run into this issue:https://github.com/pypa/pip/issues/1448where pip exit without a warning. in this case the workaround is install cygwin binutils and libuuid-develpackages, and that fixed the problem for me.)
3. install django by running pip3 install django
4. finally install the mysql driver with pip3 install mysql-connector-python --allow-external mysql-connector-python command.
now to get a django project started, try these:
django-admin.py startproject myapp
the django-admin.py script should automatically in your path. and this create a new project with initial settings. to switch default database from sqlite3 to mysql, change the myapp/settings.py with the following:
databases = { 'default': { 'name': 'mydb', 'engine': 'mysql.connector.django', 'user': 'root', 'password': 'secret', }}
now i assume you have mysql 5.6+ installed on your windows already. change the root password to match yours or using different db user. you can now have django app setup the initial database schema tables for this specif myapp with this commad:
cd myapp
python3 manage.py syncdb
follow the prompt and setup your admin user. now you can start django web app:
python3 manage.py runserver
open browser to http://localhost:8000/admin. now try to login and enjoy!
https://www.python.orghttp://cygwin.comhttp://dev.mysql.comhttps://docs.djangoproject.compublished at dzone with permission ofzemian deng, author and dzone mvb. (source)
(note: opinions expressed in this article and its replies are the opinions of their respective authors and not those of dzone, inc.)
tags:cygwindjangotips and trickspythontools & methodsbitscn.com
其它类似信息

推荐信息