登录  /  注册

Getting Django Started on Windows 7 with Python 3 and MySQL_MySQL

php中文网
发布: 2016-05-31 08:48:35
原创
1554人浏览过

pythonDjango

bitsCN.com 07.03.2014|6 views|

Related MicroZone Resources

clustrix 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-devel"packages, 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.org
  • http://cygwin.com
  • http://dev.mysql.com
  • https://docs.djangoproject.com

Published 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:
  • cygwin
  • django
  • Tips and Tricks
  • Python
  • Tools & Methods
bitsCN.com
智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号