2013年7月13日10:36:53:接上篇,bae部署django没成功,转战阿里云。。
阿里云服务器最便宜69/月,现在有个活动,新用户送20元现金券,我就花了RMB 49买了一个,操作系统选的是ubuntu1204安全加强版。
putty下载地址:http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip,解压后直接运行putty.exe即可。
Xftp下载地址http://www.onlinedown.net/soft/143.htm
以上两步看aliyun的帮助文档即可,easy,http://help.aliyun.com/manual?spm=0.0.0.0.ZERNiU&helpId=1846
管理mysql就用phpmyadmin了,这样就得再装个php,命令如下
apt-get install apache2 php5 libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin
期间要求输mysql root用户密码和phpmyadmin的登陆密码
python系统自带了。需要装python-mysqldb
apt-get install python-mysqldb
安装一个mod_wsgi,此物就是将Python应用部署到Apache上的。
apt-get install libapache2-mod-wsgi
ln -s /usr/share/phpmyadmin /var/www/phpmyadmin
python ubuntu已经自带了,需要安装一个python-mysqldb
apt-get install python-mysqldb
django从官网下载,我当前下载的版本是1.5.1,然后按照官网的说明安装。
重启Apache2的命令:
sudo /etc/init.d/apache2 restart
切换到/srv目录下,启动一个django站点
django-admin.py startproject mysite
5. 下面是配置apache了
django官方有一篇如何配置的文档,mod_wsgi官网也有如何配置的文档。主要一点mod_wsgi有两种工作模式,嵌入到Apache和作为线程的守护模式。官方推荐用守护模式,守护模式没研究,嵌入模式最简单,先用嵌入模式。
gedit /etc/apache2/sites-available/default
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> WSGIScriptAlias /app/ /srv/mysite/mysite/wsgi.py <Directory /srv/mysite/mysite> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
重点就是在原来文件的基础上增加了
WSGIScriptAlias /app/ /srv/mysite/mysite/wsgi.py <Directory /srv/mysite/mysite> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory>
还有编辑/etc/apache2/httpd.conf文件,增加下面这行
WSGIPythonPath /srv/mysite
然后重启apache服务就OK了!
此时通过浏览器访问你的云服务器主机地址xx:xx:xx:xx/app/,就可一看到django默认页面了!
编辑mysite/settings.py,修改DATABASES一项
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'db_name', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'your_mysql_passwd', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } }
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: #'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
运行下面的命令,同步数据库,为默认安装的应用创建table:
python manage.py syncdb
7.创建一个app+模型 输入下面的命令,创建一个叫polls的应用
python manage.py startapp polls
接下来创建模型(models),按照django官网教程的例子,编辑polls/models.py
from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice
这里的意思创建了两个模型:Poll、Choice。__unicode__方法是定义模型默认显示的内容。
激活模型,编辑mysite/settings.py中INSTALLED_APP,如下:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'polls', )
同步一下数据库
python manage.py syncdb
可以在shell下输入一些python语句,为模型创建内容。进入shell环境的命令为:
python manage.py shell
例如:
>>> from polls.models import Poll, Choice # Import the model classes we just wrote. # No polls are in the system yet. >>> Poll.objects.all() [] # Create a new Poll. >>> from django.utils import timezone >>> p = Poll(question="What's new?", pub_date=timezone.now()) # Save the object into the database. You have to call save() explicitly. >>> p.save() # Now it has an ID. Note that this might say "1L" instead of "1", depending # on which database you're using. That's no biggie; it just means your # database backend prefers to return integers as Python long integer # objects. >>> p.id 1
8.配置url+创建视图
编辑mysite/urls.py
urlpatterns = patterns('', # Examples: # url(r'^$', 'simple.views.home', name='home'), # url(r'^simple/', include('simple.foo.urls')), url(r'^polls/', include('polls.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), )
编辑polls/urls.py (此文件不存在,新建一个)
from django.conf.urls import patterns, url from polls import views urlpatterns = patterns('', url(r'^$', views.index, name='home'), url(r'^show/$', views.show_all, name='show'), )
创建views.index视图,编辑polls/views.py
from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the p
Centos6.4下安装Sublime Text 3
背景 1
一、 运行环境 1
二、安装环境配置 1
三、创建快捷方式 1
四、配置全局环境 2
五、操作界面 3
背景
在windows操作系统系统下,文本代码编辑器众多,各路英雄豪杰争相写了许多强大编辑器,常用的有EditPlus,UltraEdit,Source Insight,notepad等等(虽然开源免费的少,但是在中国可以用破解版),在这里不一一列举了。他们的特点是功能强大,操作相对简单,启动运行很快,支持多种不同语言。但是在linux下确鲜有强大的IDE代码编辑器,vi,vim,emacs等编辑器虽然都很强大,当时他们学习门槛高,而且需求记住许多操作命令。不利于初学者使用和推广。Linux平台下需求(类似windows)多种操作方式和能适应各种使用习惯的代码编辑器。Sublime Text 正式下如此背景情况下应运而生。
一、运行环境
操作系统:centos 6.4 64位桌面操作系统.
编辑器版本:sublime_text_3_build_3033_x64
二、安装环境配置
下载:sublime_text_3_build_3033_x64.tar.bz2
[root@localhost work]# cp -rf sublime_text_3_build_3033_x64.tar.bz2 /root/work
[root@localhost work]# tar xzvf sublime_text_3_build_3033_x64.tar.bz2
[root@localhost work]# cd sublime_text_3
[root@localhost work]# ln -s sublime_text sublime
三、创建快捷方式
在终端输入命令sublime或者【应用程序】-》【编程】选项单击就能打开SublimeText编辑器。因此,我们可以创建一个符号链接,它相当于Windows的快捷方式。
[root@localhost work]# ln -s /root/work/sublime_text_3/sublime_text /usr/bin/sublime
或者输入命令
[root@localhost work]# sublime
四、配置全局环境
要软件能像windows的【程序】--》XX软件单击,即可运行,还需要增加配置文件
/usr/local/share/applications/sublime.desktop
[root@localhost work]# cd /usr/local/share/applications/
[root@localhost work]# vim sublime.desktop
添加如下内容(标记加粗内容,是根据自己安装路径而需要修改的):
Version=1.0
Name=Sublime Text 3
GenericName=Text Editor
Exec=sublime
Terminal=false
Icon=/root/work/sublime_text_3/Icon/32x32/sublime-text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow
[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n
TargetEnvironment=Unity
五、操作界面