SAE development 01 ---- deploy Django1.7.3, 01 ---- django1.7.3 in SAE

Source: Internet
Author: User
Tags import database

SAE development 01 ---- deploy Django1.7.3, 01 ---- django1.7.3 in SAE
To apply for an application, you must have an SAE account and use Sina Weibo to register. Register and log on .................



The next step is to deploy your code using SVN. 1. Come to your SAE homepage http://sae.sina.com.cn /? M = myapp, create a new application, and select python as the development language:

2. Return to the Application List and click your application name to go to the Application Management page:

3. Choose Service Management> MySQL from the navigation bar on the left. Page appears. initialize mysql.


4. We can start to create the first version of our first application: (still on the left)-Application Management-code management, and click "Create a version here ", the version number is 1. After successful creation, you can see similar information:


The next step is to deploy your code using SVN.
Deployment 1. Now suppose you have installed SVN properly. If you don't know about SVN, click here: http://sae.sina.com.cn /? M = devcenter & content_id = 215 & catId = 212

Note! The user name used for svn check-out is your Weibo account, but the password is a secure password!

2. Check out the code folder to your local computer. The folder named after the version number is displayed. Here it should be 1.
Go to the folder 1 and find the config. yaml and index. wsgi files. Open index. wsgi in a text editor and delete all the contents. Use the following code instead.

# Coding: utf-8import saefrom pythondjangotest import wsgi # Replace pythondjangotest with your application name application = sae. create_wsgi_app (wsgi. application) # The entry to the Python application on SAE is index. wsgi: application
3. If you want to use the admin module provided by django, copy the admin media directory from the django installation directory to folder 1.
4. If you have already created a django project, directly put the folder (the project folder name must be the same as the application name created on SAE) under folder 1.
If you have not created a django project, go to folder 1 and run the python django-admin.py startpreject mysite command (replace mysite with the application name created on SAE, which will not be prompted below)
In this step, make sure that there is your django project under folder 1, that is, the mysite folder. That is, make sure that the following information is displayed in folder 1:

Index. wsgi config. yaml mysite (project folder)

5. Go to the mysite directory and modify settings. py:
Add at the beginning
Import osBASE_DIR = OS. path. dirname (OS. path. dirname (_ file _) import OS. path import sae. constfrom OS import environdebug = not environ. get ("APP_NAME", "") if debug: # use LOCAL debugging to export the database. Enter the following parameters according to the local mysql database <-------------- if the file contains Chinese characters, be sure to add # coding: UTF-8 MYSQL_DB = 'pythondjangotest' MYSQL_USER = 'root' MYSQL_PASS = '000000' MYSQL_HOST_M = '2017. 0.0.1 'mysql_host_s = '127. 0.0.1 'mysql_port = '000000' else: # SAE 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_PORT
Modify the DATABASES field:
DATABASES = {    'default': {        'ENGINE': 'django.db.backends.mysql',         'NAME': MYSQL_DB,         'USER': MYSQL_USER,         'PASSWORD': MYSQL_PASS,         'HOST': MYSQL_HOST_M,         'PORT': MYSQL_PORT,     }}
If you have set your own templates directory, add the field to TEMPLATE_DIRS.



Import database 1. mysql-python module is required for local MySQL operations,
The win system can download the installation file here with ease: (for python2.7http: // www.codegood.com/archives/129 ),
Linux is here: http://pypi.python.org/pypi/MySQL-python#downloads

2. If you have installed the mysql Service locally or you can connect to the mysql database, you can directly view the next one.
If you do not have a mysql database locally, you can install WampServer: http://www.onlinedown.net/soft/82112.htm
Follow the information in the previous section settings. py to create a database.
3. Go to the mysite directory and run python manage. py syncdb. After that, export the local database:
Go to the Management page of the local mysite database, click Export-execute at the top, and output the SQL file.
Import the exported database to the remote MYSQL database of the application created in SAE:
Go to the Application Management page of SAE> Service Management> MySQL> Manage MySQL to go To the mysql Management page of SAE. Click Import at the top-> select a file (the SQL file output just now)-> Execute



Configure the Django1.7.3 environment 1. Create the site-packages directory under the root directory
2. copy all files under the C: \ Python34 \ Lib \ site-packages \ Django-1.7.2-py3.4.egg \ django directory to site-packages \ django 3. create the application configuration file config. yaml, content:
name: pythondjangotestversion: 1libraries:- name: "django"  version: "1.7.2"handlers:- url: /static  static_dir: static

Upload and submit all the files in directory 1 to sae through svn. mysite can work now!
Do not forget to change DEBUG = True to DEBUG = False in settings. py before uploading.

Test

Is the Django version in the test version correct?


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.