Introduction to Python development and combat 17-sina Cloud Deployment

Source: Internet
Author: User
Tags tortoisesvn tortoisesvn download

17. Sina Cloud Deployment

In the previous section we described how to deploy a Python Django Web site on a local Windows Server, and this chapter briefly explains how to deploy the Python Django project to a cloud service.

In this chapter we describe how to deploy a Python Django project on Sina Cloud. First of all, we need to register Sina cloud user account, Sina cloud users now need real-name authentication, through the real-name authentication account created by the application to normal operation.

17.1. Create an App

After registering successfully login SAE, go to my homepage, click Create New app, create a new app Myseasite, develop language select Python.

17.2. Install SVN

TORTOISESVN Download: http://tortoisesvn.net/downloads.html Install SVN

17.3. Applied Code Management Create version number "1"

After creating the version, Sina Cloud itself added two files Config.yaml and Index.wsgi, now we can access our app address: http://mysaesite.sinaapp.com/

17.4. Create a code-local directory

Right-click to create a good directory mysaesite, choose SVN checkout Data Sina Cloud app code base address and local directory.

Enter the code base URL for your app's Sina cloud, such as:

Click OK, enter the code base username and password, note : User name and password for the SAE security mailbox and security password.

After the checkout command was executed, our local directory had a subdirectory of "1" with two files Config.yaml and Index.wsgi.

17.5. Using the Django Web development Framework

Several versions of Django are currently provisioned on the SAE, and the default version is 1.2.7, in this example we use the 1.4 version.

Create the App profile Config.yaml in the default version directory, and add the following to it:

1Libraries:
" Django "
" 1.4 "

Replace the contents of the Index.wsgi file as follows:

Import SAE  from Import  = Sae.create_wsgi_app (wsgi.application)
17.6. Copy the project files to the local publishing directory

We then copied the files from the previous section of the Apache local server publishing directory to the version "1" directory. Note: Deleting the mysite\inventory\static directory and repeatedly uploading static files can cause the source code to be too large.

17.7. Uploading the code to the server

Right-click the version "1" directory, select the Add command, and the new file is added.

After executing the Add version "1" The directory appears with a red exclamation mark, such as:

Right-click the version "1" directory, select SVN Commit ... command, upload the code file to the server.

Browser Browse http://mysaesite.sinaapp.com/website, error message, Sina Cloud does not support the project Sqlite3 database, now we need to use the MySQL database provided by Sina Cloud.

17.8. Add shared MySQL to the application's MySQL service, and modify the setting.py database configuration as follows.
ImportOs,sys fromSae.constImport(Mysql_host, Mysql_port, Mysql_user, Mysql_pass, mysql_db)if 'Server_software' inchOs.environ: fromSae.constImport(Mysql_host, Mysql_port, Mysql_user, Mysql_pass, mysql_db)Else: Mysql_host='w.rdc.sae.sina.com.cn'Mysql_port='3307'Mysql_user='1x150m0325'Mysql_pass='1i20xihzw23yxyj0mix0hwxh2133ijkw4133x5kk'mysql_db='App_mysaesite'     fromSae._restful_mysqlImportMonkey Monkey.patch () DATABASES= {    'default': {        'ENGINE':'Django.db.backends.mysql',        'NAME': mysql_db,'USER': Mysql_user,'PASSWORD': Mysql_pass,'HOST': Mysql_host,'PORT': Mysql_port,}}##DATABASES = {## ' default ': {## # Add ' postgresql_psycopg2 ', ' MySQL ', ' sqlite3 ' or ' Oracle '.## ' ENGINE ': ' Django.db.backends.sqlite3 ',## # Or path to database file if using Sqlite3.## ' NAME ': ' C:\\My files\\python projects\\mysite\\mysite\\mydb.db ',## # Used with Sqlite3.## ' USER ': ',## # Used with Sqlite3.## ' PASSWORD ': ',## # Set to empty string for localhost. Not used with Sqlite3.## ' HOST ': ',## # Set to empty string for default. Not used with Sqlite3.## ' PORT ': ',##    }##}

After modifying the setting.py file, we can run the Django Sync DB Command Synchronization table structure in the project so that we can see the resulting table structure in the management MySQL of Sina Cloud.

By manually adding some data to the BOM and inventory table, we can run the site to query the inventory data and verify that the release is working.

17.9. Running the website, Sina Cloud Publishing success

http://mysaesite.sinaapp.com/inventoryQuery/

17.10. Summary

In this section we demonstrate how to publish our project to "Sina Cloud" so that our project can be run on the Internet, and we will continue to extend the functionality of this website or service published by Sina to illustrate how to support the development of other services.

Introduction to Python development and combat 17-sina Cloud Deployment

Related Article

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.