Deploy django blog in Sina SAE and deploy django in sae
Steps:
Step 1:Register the Sina SAE account (Sina Weibo) and download TortoiseSVN.
Step 2:Deployment code
Use SAE to deploy code. SAE provides the PAAS-layer cloud service, that is, uploading applications directly instead of giving you a virtual host. Go to the SAE console, as shown in:
1. Create a new application:
2. Select python2.7. After the project is created successfully, return to the console and click the project to go to the Project Management page. You can use git and svn to upload code. svn is recommended here. 3. Create a version with version 1. After the creation is successful, you can see the following information.
4. Use svn to deploy code
First, create a svn folder, such as E: \ svn, in a proper location.
Then, create a folder under svn. The name is the name entered in the second-level domain name when the application is created, such as lcnet.
Right-click the pylabsite folder, select SVN Checkout, enter the URL, click "OK", enter the registered email address and password, and select "save authentication.
After that, two more folders, 1 and. svn ,. you don't need to worry about the items in svn. Focus on 1. When I first checked out, only config is in directory 1. yaml
And index. wsgi files, and then copy the local project lcnet to the 1 folder. Because SAE supports Django1.4 at most, the python installation location (for example
For example, C: \ Python27 \ Lib \ site-packages), copy the Django package and create a new site-packages folder. Remember to copy site-packages \ django
The static file under \ contrib \ admin is placed in the 1 folder. The file directory structure is as follows:
3. Modify file information:
Modify the config. yaml and index. wsgi files.
#--config.yaml--#name: lcnet2version: 2libraries:- name:"django" version:"1.8.3"handlers:- url: /foo static_dir: foo
#--index.wsgi--#import osimport sysroot = os.path.dirname(__file__)sys.path.insert(0, os.path.join(root, 'site-packages'))os.environ.setdefault("DJANGO_SETTINGS_MODULE" , "lcnet_blog.settings")from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
1/lcnet_blog/wsgi. py:
import osimport sysfrom django.core.wsgi import get_wsgi_applicationroot = os.path.dirname(__file__)sys.path.insert(0, os.path.join(root,'.','site-packages'))os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lcnet_blog.settings")application = get_wsgi_application()
1/lcnet_blog/urls. py:
#--urls--#from django.conf.urls import include, urlfrom django.contrib import adminurlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'',include('blog.urls'))]admin.autodiscover()from django.contrib.staticfiles.urls import staticfiles_urlpatternsurlpatterns += staticfiles_urlpatterns()
1/lcnet_blog/settings. py modification:
EBUG = TrueTEMPLATE_DEBUG = FalseALLOWED_HOSTS = ['.sinaapp.com',] debug = not environ. get ("APP_NAME", "") if debug: MYSQL_DB = 'lcnet' MYSQL_USER = 'root' MYSQL_PASS = 'root' MYSQL_HOST_M = '2017. 0.0.1 'mysql_host_s = '127. 0.0.1 'mysql_port = '000000' else: 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, # Database NAME 'user': MYSQL_USER, 'Password': MYSQL_PASS, # when installing the mysql database, the entered root User Password is 'host': MYSQL_HOST_M, 'Port': MYSQL_PORT ,}}
Step 4: Upload the Code:
After modifying all the items to be modified, you can upload them to SAE through svn. Right-click 1 and select SVN Commit...
The Django package has a dozen MB, but the upload speed is very slow. This process can take a rest (sae will occasionally smoke and try to upload several more times ).
Step 5: Configure Mysql:
After the above configuration is complete, the database is still empty. One way is to deploy the SAE environment locally and thenPython manage. py migrate
Synchronization to the server, but this is a tough task.
The second method is to executePython manage. py migrate,Then export the SQL statement file from the local Mysql, and then
Run the SQL statement. Here is the SQL statement file exported with Navicat for MySQL, which is very convenient.
Then you can visit yourAppName.sinaapp.com to view our labor results.
Refer:
1. http://www.sinacloud.com/doc/sae/python/tutorial.html
2. http://www.mamicode.com/info-detail-471552.html
3. http://my.oschina.net/u/877170/blog/314459? Fromerr = nY9nBubm