SAE Deployment Django1.6+mysql

Source: Internet
Author: User
Tags local time svn phpmyadmin

"Resolution" SAE Deployment Django1.6+mysql

Finally can Shu tone, today most of the time is engaged in this, is the egg ache, online data is good and bad, I do not believe this before no one did, but they did not share good enough.

Needless to say, keep a record of what you are doing today.

1, install SVN

This is nothing to say, to the official website down, all the way next loaded, but with SVN upload files to the SAE or very slow, uploading process I slept.

2, check out version to local

Prior to the deployment on the SAE, the results failed, so this time the new version, that is version 2, with SVN checked out to the local.

3, main operation

Starting from here is the point!

Just checked out version 2 to the local time, 2 directory only Config.yaml and index.wsgi two files, the project Myenrich copied over, note the directory structure,

This is local.

First ignore the Db.sqlite3 and Sqlite3.exe, these two are lightweight databases, not on the SAE, then the directory structure than two more folders: Site-packages and Static, why, the following:

    • Site-packages

Currently the default version of the SAE support Django is 1.2.7,1.4 also supported, but my project is based on 1.6.5, so here will be a bit of trouble to upload their own Django1.6.5 package.

Build yourself a site-packages folder, location, and then go to the Python installation location (e.g. C:\Python27\Lib\site-packages) to copy the Django package.

Then modify Config.yaml and Index.wsgi, as follows (basically the complete code for both files, basically, because I have other code in my file, but I think it has no effect, not a comment or code that does not work):

#--Config.yaml--#Name:myenrichversion:2libraries:-"1.6"     
#--Index.wsgi--#ImportOsImportSysroot = Os.path.dirname (__file__ '  ') importimport Saeos.environ[ ' myenrich.settingsapplication = Sae.create_wsgi_app (Django.core.handlers.wsgi.WSGIHandler ())      

Attention:

First of all, the code here to itself according to their own situation to change, I this and online slightly different, because the directory structure of the relationship, my site-packages and INDEX.WSGI, etc. are at a directory level, Then my sys.path.insert write, if not this level, then you need to change the Sys.path.insert () function in the Os.path.join (Roo, ' * ', ' site-packages ') of the "*" Part! This flexible change is very important, otherwise can not find the path, nothing is useless.

In addition, root and Sys.path.insert do not import Django, or even Django can not find, import who go.

Finally, os.environ[' django_settings_module ' = ' myenrich.settings ', here the Myenrich is their own project name, perhaps also related to the directory structure, this can be seen.

In fact, I have changed the 2/myenrich/wsgi.py, but I do not know if it works no, paste the code bar

ImportOsImportSysroot = Os.path.dirname (__file__) Sys.path.insert (0, Os.path.join (Root,‘..‘,‘Site-packages‘))#We defer to a django_settings_module already in the environment. This breaks#If running multiple sites in the same MOD_WSGI process. To fix this, use#Mod_wsgi daemon mode with all site in it own daemon process, or use#os.environ["Django_settings_module"] = "mysite.settings" Os.environ.setdefault ("Django_settings_module","Myenrich.settings")# This Application object was used by any WSGI server Configured to use This# file. This includes Django ' s development Server, if the Wsgi_application# setting points here. from django.core.wsgi import  Get_wsgi_applicationapplication = get_wsgi_ Application () # Apply WSGI middleware Here.# from Helloworld.wsgi import helloworldapplication#< Span style= "color: #008000;" > application = helloworldapplication (application)          

To do this, should be able to run up, but other problems come, although can run up, CSS and JS is invalid, through the review element found link wrong.

Oh, yes, the afternoon configuration when there is no django.middleware.clickjacking problem, I do not understand what it is for, so I directly in the 2/myenrich/settings.py to comment it out.

Middleware_classes =(‘Django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', #' Django.middleware.csrf.CsrfViewMiddleware ', 'django.contrib.auth.middleware.AuthenticationMiddleware ', 'django.contrib.messages.middleware.MessageMiddleware', #' Django.middleware.clickjacking.XFrameOptionsMiddleware ',)          
    • Static

Before the local time is no problem, the SAE find CSS and JS method and the local difference, anyway, according to its meaning to change, so I put the static folder out, put in the root directory.

4, configure the database

The last step to configure the database, the local original is the use of Django and MySQL, this step is not really a problem.

With Wamp phpMyAdmin into the project database to export to SQL format, there is an episode, Wamp start Green, it is because the project before the time IIS opened, took up 80 ports, IIS off the good.

Configure the database as long as you want to change the 2/myenrich/settings.py file!

A. Add the following code to your head

ImportOs.pathImportSae.constFrom OSImportEnviron#debug = Not Environ.get ("App_name", "" ")#If debug:#mysql_db = ' Myenrich '#Mysql_user = ' root '# Mysql_pass = ' # Mysql_ host_m = ' 127.0.0.1 ' # mysql_host_s = ' 127.0.0.1 ' # Mysql_port = ' 3306 ' ##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             

I'm not going to let it debug right here.

B. Modifying the Databases field

DATABASES ={‘Default‘: {#' ENGINE ': ' Django.db.backends.sqlite3 ',#' NAME ': Os.path.join (Base_dir, ' db.sqlite3 '),
#' ENGINE ': ' Django.db.backends.mysql ',#' NAME ': ' Myenrich ',#' USER ': ' Root ',#' PASSWORD ': ',#' HOST ': ',#' PORT ': ' 3306 ',
‘ENGINE‘:‘django.db.backends.mysql ' name : mysql_db, ' user: Mysql_user, ' password ' : Mysql_pass, host ' : Mysql_host_m,

The first two lines are the previously used sqlite3 code, the middle comment part is the local MySQL method, the SAE is not annotated at the bottom.

Here's the NAME AH user ah is clearly used in step a defined variables, the online tutorial actually has a similar ' NAME ': ' mysql_db ' of the writing, at first did not pay attention to the loss.

Here the code is finished, to the SAE corresponding project "service Management"-"MySQL"-"Manage MySQL", the previously exported SQL file can be imported.

--Update 2015-08-01

It is important to note that I use the Django version is 1.8, where the default established database uses DateTime in the form of datetime (6), and the SAE does not support DateTime followed by parentheses, possibly the version is older.

Because I have exported the SQL script locally phpmyadmin to datetime (6) so that it can be imported into the SAE MySQL successfully.

Use SVN to synchronize the changes, and then access the corresponding URLs, there should be no problem.

Configuration process is very difficult, record blog when not remember every step and make all the mistakes, blog is just a reference, since it has been furnished, I think the most important is the configuration process of their own thinking, rather than rigidly follow the online tutorial step down, at least to know the meaning of each step, Learn to identify and correct your own mistakes in online tutorials and see the light from the fog.

SAE Deployment Django1.6+mysql

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.