Python path-----web App Creation (python3.4, Django connection MySQL)

Source: Internet
Author: User

Reference URL:
https://github.com/PyMySQL/PyMySQL/

A Web site in the Django Framework can contain multiple Django projects, while a Django project contains a specific set of objects, including the design of the URL, the design of the database, and other options.
django-admin.py-----It has a number of command options that you can use to manipulate the project. With the startproject command option, you can generate a directory of project names that includes the file structure needed for a basic Web application:
__init__.py: Empty file, used primarily to tell Python to use this site directory as a python package
manage.py: Allows site administrators to manage Django projects
Configuration file for Settings.py:django project
urls.py: Write a configuration file that includes a URL, which is how users access the Django app

Attention:
(1) The Django project is handled as a Python package, so when the project is named, try not to conflict with the name in the existing Python module.

1. Create a new project and an app
Attention:
(1) When performing python3.4 manage.py startapp firstapp: Importerror:no module named ' MySQLdb '
The Python standard library does not have an integrated MySQL interface program, and MySQLdb is a third-party package that needs to be downloaded and installed separately. Currently MYSQLDB does not support python3.x, can install Pymysql instead of Mysql-python.
# yum-y Install mysql-python.x86_64 # #安装后, you must recompile python, but use the default python.
For Connector/python 2.0, the source tree had been reorganized to having a single code base, for easier maintenance, testing , and distribution.
# tar XVF mysql-connector-python-2.0.4.tar.gz
# python3.4 setup.py Install--help
# python3.4 setup.py Install
Copying build/lib/mysql/connector/catch23.py-/usr/local/python3.4.3/lib/python3.4/site-packages/mysql/ Connector
(2) manage.py when creating an app, it reads the settings.py configuration
(3) Pymysql.err.InternalError: (1130, "Host":: 1 ' isn't allowed to connect to this MySQL server ")
Databases settings password options must be in uppercase

# mkdir-p/www/django/
# python3.4/usr/local/python3.4.3/bin/django-admin.py Startproject firstproject/www/django/# #创建firstproject的目录

#The last stable release was available on PyPI and can being installed with PIP
#/usr/local/python3.4.3/bin/pip3.4 Install Pymysql
Downloading PYMYSQL-0.6.6-PY2.PY3-NONE-ANY.WHL
# Vim firstproject/__init__.py
Import Pymysql
Pymysql.install_as_mysqldb ()

# pwd
/www/django/firstproject
# Vim settings.py
DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ', # #数据库引擎
' NAME ': ' Django ', # #数据库名
' USER ': ' YANGSQ ',
' PASSWORD ': ' 123456 ',
' HOST ': ' 192.168.0.3 ',
' PORT ': ' 3306 ',
}
}
# python3.4 manage.py Startapp Firstapp
# python3.4 manage.py syncdb # #创建配置文件INSTALLED_APPS域中还没有创建的表
2. A lightweight Web application server in the Django framework
The Django built-in server can be loaded automatically when the code is modified, enabling rapid website development.

# python3.4 manage.py runserver 0.0.0.0:8000 & # #使用http://192.168.0.4:8000/Visit Web page


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python path-----web App Creation (python3.4, Django connection MySQL)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.