In order to keep pace with the times, work idle began to study Python, just a touch on the python this "elegant" syntax to attract! Later, Django, although not much in-depth research, but the new concept of web development is very interested in, decided to try to use it instead of Java development of small background programs, learn it by the side!
Note: This article only introduces the basic building process, is not responsible for explaining, because just contact Python I do not understand!
First, the Python environment version used by SAE
Python2.7
django1.27/1.4/1.5
Local version to be sure, you need to use other pre-assembled modules to be sure.
(I started with a high version of Python and Django, and there was a whole bunch of inexplicable mistakes.) )
Second, SAE registration, configuration
Sign up, create a new app, and when you're done creating a code version in code management, the SAE allows multiple versions of the code to exist and can be switched to each other.
SAE uses SVN to manage the Python source code, the page at the bottom of the source code of the SVN address, is "https://svn.sinaapp.com/< your app name >" format, SVN account password for the security mailbox, security password
SVN client http://tortoisesvn.net/downloads.html
The root directory is based on the code version, and there should be only one folder labeled "1", where only: Config.yaml,index.wsgi two files.
Create a Django project under the "1" folder and enter it on the command line:
django-admin.py Startproject < your app name >
this will produce a two-level path named after your app, copying subdirectories and manage.py into a directory
At this point the root directory has Config.yaml, Index.wsgi, manage.py, <app names > folders
<app name > Folder with __init__.py, setting.py, urls.py, wsgi.py
Third, modify the contents of Config.yaml, Index.wsgi:
Config.yaml:
Name: < your app name >version:1libraries:-Name: "Django" version: "1.5" #我使用的是Django1.5
INDEX.WSGI:
Import OS import django.core.handlers.wsgiimport saeos.environ[' django_settings_module ' = ' < your app name;. Settings ' application = Sae.create_wsgi_app (Django.core.handlers.wsgi.WSGIHandler ())
Iv. Commissioning of Django
It is recommended to use Pycharm as the IDE for development.
: http://www.jetbrains.com/pycharm/
Install the SAE in the native simulation environment.
: https://github.com/sinacloud/sae-python-dev-guide.git
Execute python setup.py install in Dev_server
If "No module name Setuptools" appears, the missing Setuptools
: https://bootstrap.pypa.io/ez_setup.py
Save it and do the following, it will be installed automatically.
Modify the database link in setting.py and add and modify the following code:
Import os.pathfrom OS Import environdebug = Not environ.get ("App_name", "") if debug: #LOCAL when the code is running locally, link the local database, configure it Yourself mysql_db = ' App_saepy ' mysql_user = ' root ' mysql_pass = ' admin ' mysql_host_m = ' 127.0.0.1 ' mysql_host_ S = ' 127.0.0.1 ' mysql_port = ' 3306 ' else: #SAE when the code runs on the cloud platform, link to the cloud database, the parameters of the link are all in sae.const import sae.const mysql_db = Sae.const.MYSQL_DB mysql_user = Sae.const.MYSQL_USER mysql_pass = Sae.const.MYSQL_PASS MYSQL _host_m = Sae.const.MYSQL_HOST mysql_host_s = Sae.const.MYSQL_HOST_S mysql_port = sae.const.MYSQL_ portdatabases = {' default ': { ' ENGINE ': ' Django.db.backends.mysql ', ' NAME ': mysql_db, ' USER ': Mysql_user, ' PASSWORD ': Mysql_pass, ' HOST ': mysql_host_m, ' PORT ': Mysql_port, }}
To test our open Django built-in admin, modify urls.py and setting.py.
Start the service locally by command, or through Pycharm
manage.py Runserver 8000
You should be able to access the Django program through localhost:8000.
Note that the SAE MySQL seems to be safe, and is not allowed to be accessed with tools such as Navicat. Using the SYNCDB command to synchronize the SAE database is also cumbersome, and the solution is typically to use the SYNCDB command locally, then dump the local database into a SQL file and execute it on the SAE MySQL, which is much more convenient. (Before using the SAE MySQL, remember to initialize the database in service management.) )
By using SVN to upload a locally configured Django project, the <app name >.sinaapp.com/admin/should already be accessible, but the admin interface is in a state where there is no CSS at all. This is a static file that Django cannot find the admin, there are many ways to solve it, in the official documentation, it is easier to copy the static files used by admin to "1" (< in the Django installation path >\django\contrib\ Admin\static under the Admin folder), after you upload via SVN.