In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to deploy Python+Django applications on SAE, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
As I said before, I want to do my own blog, while spending less money and doing less (hehe, too lazy), so I chose Python+Django. After a few days of twists and turns, I finally finished it, and I couldn't wait to deploy it to SAE, so I can't wait to share the deployment process.
1. Preparatory work
Of course, the most important thing in the preparation work is to prepare your own application code, nonsense, the code is the most important, but I want to skip it. Friends who don't know can refer to the Django wizard (nonsense again) and do it step by step. In fact, in the preparation phase, I think the most important thing is some configuration on SAE.
First of all, you need to build your own application on SAE and download it to the local machine using SVN. If you want to use a simulated SAE environment on this machine, you also need to download and install the SAE local development package. Then copy everything from your code root to directory 1 under the SVN directory. The specific operation commands are as follows:
Svn co https://svn.sinaapp.com/your_app_name
The above is the download application code. Assuming that the root directory of your local code is mysite, you need to do the following:
Cp mysite/* your_app_name/1
In that case, the preparatory work will be done. I have said a lot before, but in fact, there are only two words that are useful.
2. Configuration file compilation
There are two main configuration files for SAE: config.yaml and index.wsgi. All we have to do is create these two files in the root directory, and then edit them according to the actual situation of the application.
All right, stop it. Code it.
The first is index.wsgi, which is the standard SAE template and has nothing complicated except to change the application name to your own.
Import sys import os.path os.environ ['DJANGO_SETTINGS_MODULE'] =' YOUR_APP_NAME.settings' sys.path.append (os.path.join (os.path.dirname (_ _ file__), 'YOUR_APP_NAME')) import sae from YOUR_APP_NAME import wsgi application = sae.create_wsgi_app (wsgi.application)
Note: simply replace the YOUR_APP_NAME with the name of your application, do not add any other symbols
Next, let's take a look at config.yaml. The configuration of this file is relatively complicated, but there is nothing too complicated. As long as you understand the meaning of each of these configuration options, everything is easy. If there is anything unclear, you can refer to the SAE application configuration documentation. Let's take a look at our initial configuration file first.
Name: YOUR_APP_NAME version: 1 libraries:-name: django version: "1.5"
Ha ha, or simply do some replacement, YOUR_APP_NAME or simply replace with the name of your application; in addition, there is a reference library configuration, my application used the django framework, so need to introduce, at the same time, I use the version is 1.5, so please remember, set its version to 1.5, if you are using version 1.4, be sure to set it to version 1.4, otherwise. Oh, of course, you can report a lot of mistakes.
This is the end of the configuration file, So easyweights! Isn't it?
3. Static file processing
When dealing with static files, it is also troublesome to say that it is troublesome, but it is really easy to do it, as long as it is simple to use it. Based on the ability to use it, I simply deal with static files.
First of all, please make sure that you have not changed the settings related to static files in the setting file in the application. To put it simply, all settings that start with STATIC have not changed.
The next step is to execute the django static file collection command, just execute the following command from the root of your application.
. / manage.py collectstatic
There will be a message for you to confirm, just type "yes".
Finally, open the config.yaml file again and add the following code:
Handlers:- url: / static/ static_path:. /
4. Database settings
I can't imagine what an application would be like without the support of a database in the current environment. No matter what other people do, my application will use a database, and of course I still have to use MySQL. The configuration of the database is very simple, and basically does not need to be moved after the configuration. Oh, what are you smirking about? don't do it yet.
First, open the settings.py file and add the following code before the original DATABASES configuration:
If 'SERVER_SOFTWARE' in os.environ: from sae.const import (MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASS, MYSQL_DB) else: MYSQL_HOST =' localhost' MYSQL_PORT = '3306' MYSQL_USER = 'root' MYSQL_PASS =' * 'MYSQL_DB =' YOUR_DATABASE_NAME'
Then change the original DATABASES configuration to the following code:
DATABASES = {'default': {' ENGINE': 'django.db.backends.mysql', # Add' postgresql_psycopg2', 'mysql',' sqlite3' or 'oracle'. 'NAME': MYSQL_DB, # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: 'USER': MYSQL_USER,' PASSWORD': MYSQL_PASS, 'HOST': MYSQL_HOST, # Empty for localhost through domain sockets or' 127.0.0.1 'for localhost through TCP. 'PORT': MYSQL_PORT, # Set to empty string for default. }}
Finally, don't forget to enable MySQL database support in SAE. This allows you to run applications both in the SAE environment and in a native SAE-free simulation environment.
OK, now that you are done, execute the following command:
Svn add * svn ci-m "Deploy app into SAE" after reading the above, have you mastered how to deploy Python+Django applications on SAE? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.