月度归档:2011年07月

Django set up at Bluehost(同时学会怎样在bluehost里安装python的webpy)

从下面信息,学会了在bluehost里安装python的webpy。
也就是需要设置python的路径,2.4里export PYTHONPATH=$HOME/.local/lib/python/:$PYTHONPATH
2.6之后的export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH

中间还碰到web.py的application.py中一句报错,结果发现是2.4.3版本下就是有问题,只好将这句屏蔽
#SUFFIX = ‘$py.class’ if sys.platform.startswith(‘java’) else ‘.pyc’
修改成
SUFFIX = ‘.pyc’
这样至少可以import web 不报错了。

7.27 增加内容:
本来想直接用bluehost里的2.4.3版本python,后来发现那样web.py还是无法使用,所以最终还是按照下文重新安装了2.7版本的python。当然,那句原来import web报错的语句也就不用改了。

Django set up at Bluehost
Using Django on Bluehost
This is a brief tutorial showing how to set up Django for either development or deployment of Django applications on Bluehost. It is not a Django tutorial. The official Django documentation includes a tutorial as well as documentation on just about every feature that Django offers.

Django is a web framework that makes it easy for developers to rapidly create complete web applications using best practices, and a clean design. It has a database abstraction layer built in, a templating engine, an automatic admin interface, and much more.

Pre-requisites
You will need SSH access to use Django.
Optionally, you can install your own version of Python into your home directory. This is not required, but can be done if you choose. All versions of Python run by any Bluehost server can run Django.
If you choose to install your own version of Python, configure it with a prefix of $HOME/.local to follow along with this guide.
Installing Django
Django itself is just a bunch of Python code. The way that Python code is made accessible by Python is by putting it into a directory that is on the Python path.

The Python Path is a list of directories that Python will look in when searching for Python code. You can see this list of directories that your Python interpretor will use by starting python on the command line, and typing import sys; sys.path.

Due to a few differences in Python 2.6, the instructions are slightly different for installation. To find out what version of Python you are running, type python -V at the command line.

Warning

Installing Django puts many additional files into your account. Please ensure that you do not exceed the file count limit.

Python 2.6 and newer

Note

Bluehost does provide a copy of Python 2.6. If want to use that copy of Python, you’ll need to invoke it with the command python2.6 instead of invoking it as python.

As of Python 2.6, default location for user-specific Python code in your home directory is ~/.local/lib/python2.6/site-packages/. This directory is where we will install Django.

Now, you are ready to download and install the Django code to this directory. The latest release of Django is available from http://www.djangoproject.com/download/. Go ahead and download the latest version of Django to your home directory, and untar it:

$ wget http://www.djangoproject.com/download/1.2.1/tarball/
$ tar xzvf Django-1.21.tar.gz
$ cd Django-1.2.1
This is the Django distribution tree. Installation is easy:

$ python setup.py install –user
Django installs some commands that you can use in your bash shell. To make sure these work, add the following to the end of your .bashrc file:

export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
Log out and log back in to effect this change.

Python 2.3, 2.4, or 2.5

First, we need a directory for Python code to reside in your home directory. Python 2.6 has made a standard for doing this, but you can follow the new convention with older versions of Python as well. Create this directory by doing the following:

mkdir -p ~/.local/lib/python/
Now, we need to put this directory on your Python path. To do this, add the following to the bottom of your ~/.bashrc file using a text editor:

export PYTHONPATH=$HOME/.local/lib/python/:$PYTHONPATH
Re-log in to your session to effect this change.

Now, you are ready to download and install the Django code to this directory. The latest release of Django is available from http://www.djangoproject.com/download/. Go ahead and download the latest version of Django to your home directory, and untar it:

$ wget http://www.djangoproject.com/download/1.1/tarball/
$ tar xzvf Django-1.1.tar.gz
$ cd Django-1.1
This is the Django distribution tree. Installation is easy:

$ python setup.py install –home $HOME/.local
Django installs some commands that you can use in your bash shell. To make sure these work, add the following to the end of your .bashrc file:

export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
Log out and log back in to effect this change.

Testing Your Installation
You can test your installation of Django to see if it worked by starting the Python interpretor by typing python at the command prompt and hitting enter. You’ll get the Python interactive interpretor, where you can type import django and hit enter. If it gives an error, then there is a problem with your installation. If no error is given, then you’ve successfully installed Django to your Python path. Go ahead and exit the Python shell by typing ctrl+d.

If you were unable to import Django, try re-logging in to your shell, and try again. If it still doesn’t work, double check to make sure that your Python path is correct, and that Django really resides in a directory on the Python Path. To see what this list of directories is, start up the Python interpretor, and type “import sys; sys.path”, and press enter. This should give you a list of directories. This should include any directories you listed in your .bashrc file for PYTHONPATH. Check for any typos in your .bashrc file. As long as the django directory is in one of those directories listed, then you should be able to do the import. If it isn’t in any of those directories, try re-installing Django.

You’ll also want to test the django-admin.py command by trying to run it from your shell. You should get a usage message with a list of management commands that can be run. If you get “command not found”, then there was a problem with the installation of Django.

To diagnose a “command not found”, double check that there are no typos in your .bashrc file for the PATH variable that you added. Re-log in to ensure that this .bashrc change is taking place. Type echo $PATH at the command prompt to get a list of directories on your path. The django-admin.py file should be in your ~/.local/bin directory. If it isn’t in that directory, try re-installing Django.

Installing Support Libraries
Django comes with plenty to get your site working out of the box, but it also needs some support libraries for some functionality. Each of these support libraries come with their own set of instructions for installation, and in many cases, the setup.py method can be used.

You will at least need the flup library to get Django working on Bluehost. You may also need one or more of MySQLdb, sqlite3, or psycopg2. Depending what database you plan on using, what version of Python you are running, or what is already installed server-wide.

You can download the latest version of flup from http://www.saddi.com/software/flup/dist/. Once downloaded, the install process is the same as it was for Django itself:

$ wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
$ tar xzvf flup-1.0.2.tar.gz
$ cd flup-1.0.2
For Python 2.6 and higher:

$ python setup.py install –user
For Python 2.3-2.5:

$ python setup.py install –home $HOME/.local
Follow this process for any other Python modules you will need for your project.

You can test the installation of any Python package/module by using the same method described to test Django’s installation. Start up a Python interactive interpretor by typing python, and then type import , where is the name of the module you are testing.

Your Django Application
Your Django application is also Python code, just like django and flup. Go ahead and put your Django project directory into ~/.local/lib/python2.6/site-packages or ~/.local/lib/python, depending on the version of Python you are running. Once there, you will be ready to actually deploy your Django application using Apache/FastCGI.

If you don’t yet have a Django project that you are ready to deploy, you should be far enough along to start developing one, or find one online that suits your needs. The official Django tutorial is a good starting point if you are trying to get started with Django development.

The instructions in the official Django documentation for deploying Django on shared hosting using FastCGI work perfectly on Bluehost. The official instructions are here: http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache

Essentially, you need two components to make this work. The first thing you need is a fastcgi script, written in Python, that loads your Django application and starts the FastCGI listener. The other component is a .htaccess file with the appropriate code to point Apache at your FastCGI script. Here is a (slightly) modified copy of the FastCGI deployment Python script from the Django documentation. This example assumes your Django project is called myproject, but you should update it to be whatever your project name really is. Copy the following code, and put it into a file called mysite.fcgi, updating it to reflect your project:

#!/usr/bin/python
import sys, os

# Add a custom Python path.
sys.path.insert(0, “/home/username/.local/lib/python”)

# Switch to the directory of your project. (Optional.)
# os.chdir(“/home/user/myproject”)

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ[‘DJANGO_SETTINGS_MODULE’] = “myproject.settings”

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method=”threaded”, daemonize=”false”)
Please note that you may need to have additional Python path locations. Simply add additional instances of the sys.path.insert(0, “/full/path/to/path”) lines for each location you need to add. If any of the support libraries you install are installed as eggs, you may need to add the full path to the egg. The flup module falls into this category.

Make the mysite.fcgi file executable by setting the permissions to 0755. Please note that if you are using a different or a custom version of Python, that you should update /usr/bin/python on the first line to reflect the real location.

Place the mysite.fcgi file into the directory of the domain you want your Django project hosted in. For your main domain, this will be public_html. If it is an add-on domain, or a subdomain, it will be in the directory that corresponds with that domain.

Next, we’ll need to set up a rewrite rule so you won’t see mysite.fcgi in your URL. This is done by putting some configuration directives into your .htaccess file.

The .htaccess file is a file for directory-specific configuration options on your account. If you don’t have a .htaccess file, go ahead and create a blank one using any text editor. This .htaccess file should be in the same directory as your mysite.fcgi file.

A generic introduction to the .htaccess file, along with several examples can be found at: /cgi/help/115

Put the following code into your .htaccess file to complete the configuration of your Django application:

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]

Django set up at Bluehost (同时学会怎样在bluehost里安装python的webpy)

从下面信息,学会了在bluehost里安装python的webpy。
也就是需要设置python的路径,2.4里export PYTHONPATH=$HOME/.local/lib/python/:$PYTHONPATH
2.6之后的export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH

中间还碰到web.py的application.py中一句报错,结果发现是2.4.3版本下就是有问题,只好将这句屏蔽
#SUFFIX = ‘$py.class’ if sys.platform.startswith(‘java’) else ‘.pyc’
修改成
SUFFIX = ‘.pyc’
这样至少可以import web 不报错了。

7.27 增加内容:
本来想直接用bluehost里的2.4.3版本python,后来发现那样web.py还是无法使用,所以最终还是按照下文重新安装了2.7版本的python。当然,那句原来import web报错的语句也就不用改了。

Django set up at Bluehost
Using Django on Bluehost
This is a brief tutorial showing how to set up Django for either development or deployment of Django applications on Bluehost. It is not a Django tutorial. The official Django documentation includes a tutorial as well as documentation on just about every feature that Django offers.

Django is a web framework that makes it easy for developers to rapidly create complete web applications using best practices, and a clean design. It has a database abstraction layer built in, a templating engine, an automatic admin interface, and much more.

Pre-requisites
You will need SSH access to use Django.
Optionally, you can install your own version of Python into your home directory. This is not required, but can be done if you choose. All versions of Python run by any Bluehost server can run Django.
If you choose to install your own version of Python, configure it with a prefix of $HOME/.local to follow along with this guide.
Installing Django
Django itself is just a bunch of Python code. The way that Python code is made accessible by Python is by putting it into a directory that is on the Python path.

The Python Path is a list of directories that Python will look in when searching for Python code. You can see this list of directories that your Python interpretor will use by starting python on the command line, and typing import sys; sys.path.

Due to a few differences in Python 2.6, the instructions are slightly different for installation. To find out what version of Python you are running, type python -V at the command line.

Warning

Installing Django puts many additional files into your account. Please ensure that you do not exceed the file count limit.

Python 2.6 and newer

Note

Bluehost does provide a copy of Python 2.6. If want to use that copy of Python, you’ll need to invoke it with the command python2.6 instead of invoking it as python.

As of Python 2.6, default location for user-specific Python code in your home directory is ~/.local/lib/python2.6/site-packages/. This directory is where we will install Django.

Now, you are ready to download and install the Django code to this directory. The latest release of Django is available from http://www.djangoproject.com/download/. Go ahead and download the latest version of Django to your home directory, and untar it:

$ wget http://www.djangoproject.com/download/1.2.1/tarball/
$ tar xzvf Django-1.21.tar.gz
$ cd Django-1.2.1
This is the Django distribution tree. Installation is easy:

$ python setup.py install –user
Django installs some commands that you can use in your bash shell. To make sure these work, add the following to the end of your .bashrc file:

export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
Log out and log back in to effect this change.

Python 2.3, 2.4, or 2.5

First, we need a directory for Python code to reside in your home directory. Python 2.6 has made a standard for doing this, but you can follow the new convention with older versions of Python as well. Create this directory by doing the following:

mkdir -p ~/.local/lib/python/
Now, we need to put this directory on your Python path. To do this, add the following to the bottom of your ~/.bashrc file using a text editor:

export PYTHONPATH=$HOME/.local/lib/python/:$PYTHONPATH
Re-log in to your session to effect this change.

Now, you are ready to download and install the Django code to this directory. The latest release of Django is available from http://www.djangoproject.com/download/. Go ahead and download the latest version of Django to your home directory, and untar it:

$ wget http://www.djangoproject.com/download/1.1/tarball/
$ tar xzvf Django-1.1.tar.gz
$ cd Django-1.1
This is the Django distribution tree. Installation is easy:

$ python setup.py install –home $HOME/.local
Django installs some commands that you can use in your bash shell. To make sure these work, add the following to the end of your .bashrc file:

export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
Log out and log back in to effect this change.

Testing Your Installation
You can test your installation of Django to see if it worked by starting the Python interpretor by typing python at the command prompt and hitting enter. You’ll get the Python interactive interpretor, where you can type import django and hit enter. If it gives an error, then there is a problem with your installation. If no error is given, then you’ve successfully installed Django to your Python path. Go ahead and exit the Python shell by typing ctrl+d.

If you were unable to import Django, try re-logging in to your shell, and try again. If it still doesn’t work, double check to make sure that your Python path is correct, and that Django really resides in a directory on the Python Path. To see what this list of directories is, start up the Python interpretor, and type “import sys; sys.path”, and press enter. This should give you a list of directories. This should include any directories you listed in your .bashrc file for PYTHONPATH. Check for any typos in your .bashrc file. As long as the django directory is in one of those directories listed, then you should be able to do the import. If it isn’t in any of those directories, try re-installing Django.

You’ll also want to test the django-admin.py command by trying to run it from your shell. You should get a usage message with a list of management commands that can be run. If you get “command not found”, then there was a problem with the installation of Django.

To diagnose a “command not found”, double check that there are no typos in your .bashrc file for the PATH variable that you added. Re-log in to ensure that this .bashrc change is taking place. Type echo $PATH at the command prompt to get a list of directories on your path. The django-admin.py file should be in your ~/.local/bin directory. If it isn’t in that directory, try re-installing Django.

Installing Support Libraries
Django comes with plenty to get your site working out of the box, but it also needs some support libraries for some functionality. Each of these support libraries come with their own set of instructions for installation, and in many cases, the setup.py method can be used.

You will at least need the flup library to get Django working on Bluehost. You may also need one or more of MySQLdb, sqlite3, or psycopg2. Depending what database you plan on using, what version of Python you are running, or what is already installed server-wide.

You can download the latest version of flup from http://www.saddi.com/software/flup/dist/. Once downloaded, the install process is the same as it was for Django itself:

$ wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
$ tar xzvf flup-1.0.2.tar.gz
$ cd flup-1.0.2
For Python 2.6 and higher:

$ python setup.py install –user
For Python 2.3-2.5:

$ python setup.py install –home $HOME/.local
Follow this process for any other Python modules you will need for your project.

You can test the installation of any Python package/module by using the same method described to test Django’s installation. Start up a Python interactive interpretor by typing python, and then type import , where is the name of the module you are testing.

Your Django Application
Your Django application is also Python code, just like django and flup. Go ahead and put your Django project directory into ~/.local/lib/python2.6/site-packages or ~/.local/lib/python, depending on the version of Python you are running. Once there, you will be ready to actually deploy your Django application using Apache/FastCGI.

If you don’t yet have a Django project that you are ready to deploy, you should be far enough along to start developing one, or find one online that suits your needs. The official Django tutorial is a good starting point if you are trying to get started with Django development.

The instructions in the official Django documentation for deploying Django on shared hosting using FastCGI work perfectly on Bluehost. The official instructions are here: http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache

Essentially, you need two components to make this work. The first thing you need is a fastcgi script, written in Python, that loads your Django application and starts the FastCGI listener. The other component is a .htaccess file with the appropriate code to point Apache at your FastCGI script. Here is a (slightly) modified copy of the FastCGI deployment Python script from the Django documentation. This example assumes your Django project is called myproject, but you should update it to be whatever your project name really is. Copy the following code, and put it into a file called mysite.fcgi, updating it to reflect your project:

#!/usr/bin/python
import sys, os

# Add a custom Python path.
sys.path.insert(0, “/home/username/.local/lib/python”)

# Switch to the directory of your project. (Optional.)
# os.chdir(“/home/user/myproject”)

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ[‘DJANGO_SETTINGS_MODULE’] = “myproject.settings”

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method=”threaded”, daemonize=”false”)
Please note that you may need to have additional Python path locations. Simply add additional instances of the sys.path.insert(0, “/full/path/to/path”) lines for each location you need to add. If any of the support libraries you install are installed as eggs, you may need to add the full path to the egg. The flup module falls into this category.

Make the mysite.fcgi file executable by setting the permissions to 0755. Please note that if you are using a different or a custom version of Python, that you should update /usr/bin/python on the first line to reflect the real location.

Place the mysite.fcgi file into the directory of the domain you want your Django project hosted in. For your main domain, this will be public_html. If it is an add-on domain, or a subdomain, it will be in the directory that corresponds with that domain.

Next, we’ll need to set up a rewrite rule so you won’t see mysite.fcgi in your URL. This is done by putting some configuration directives into your .htaccess file.

The .htaccess file is a file for directory-specific configuration options on your account. If you don’t have a .htaccess file, go ahead and create a blank one using any text editor. This .htaccess file should be in the same directory as your mysite.fcgi file.

A generic introduction to the .htaccess file, along with several examples can be found at: /cgi/help/115

Put the following code into your .htaccess file to complete the configuration of your Django application:

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]

wordpress常见问题集锦

今日又在装wp,却发现以前碰到的几个问题都忘记怎么解决的了,只好重新网上找。现在把常见的问题留档下来,以备以后查阅。

http://cn.wordpress.org/switching/
如何把wordpress界面改成中文?
下面步骤指导您将现有的英文 WordPress 站点切换为中文。
通过 FTP、SSH 等方式打开并编辑站点根目录下的 wp-config.php 文件。
查找 define(‘WPLANG’, ”); 一行,在第二个参数处填入 zh_CN,变成 define(‘WPLANG’, ‘zh_CN’); 并保存文件。
进入站点控制板(dashboard),看到更新提示后进行升级即可。WordPress 会自动从官方网站下载中文语言包并安装。
11.15日补充:近日安装一个wp,结果发现前面几步做完后,并没有切换到中文,后来又到wp-content里,把另一个已经装好的整个languages目录全部copy过来,才ok!

http://www.ludou.org/why-wordpress-cant-send-mail.html
为什么在后台注册,WordPress没有给用户发送注册信息的Email?
为什么我已经安装了相关插件,但是WordPress没有给评论者发送新评论通知?
其实这都涉及到了一个问题:为什么WordPress无法发送Email?

通常这样的问题大都是博客空间引起的,而不是WordPress程序的问题。要想查清楚WordPress不能发信是不是由博客空间引起的,可以使用以下方法检测。新建一个php文件,命名为 mail.php ,打开并填上以下代码:

保存并上传至你的网站根目录,并在浏览器运行:
http://你的博客网址/mail.php

到你的邮箱查收邮件,如果收到标题为 My subject 的邮件,说明你的空间支持mail()函数发送邮件,也就是WordPress默认的发信方式。如果未收到任何邮件,说明你的网站空间不支持mail()发信,这也就是为什么WordPress无法发送邮件的原因了,找你的博客空间客服谈谈吧。

python cgi例子程序

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb; cgitb.enable()

print(“Content-Type: text/plain;charset=utf-8″)
print()

print(“Hello World!”)

以前一直在自己的bluehost空间想运行python程序而失败,从网上搜索了大量的文档,改.htaccess配置等。
最后发现bluehost早已经配置好python环境了,只是以前写的.py文件不合规罢了。上面就是标准例程。
注意如果是低版本python,要用print “”代替 print()

python cgi 例子程序

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb; cgitb.enable()

print(“Content-Type: text/plain;charset=utf-8″)
print()

print(“Hello World!”)

以前一直在自己的bluehost空间想运行python程序而失败,从网上搜索了大量的文档,改.htaccess配置等。
最后发现bluehost早已经配置好python环境了,只是以前写的.py文件不合规罢了。上面就是标准例程。
注意如果是低版本python,要用print “”代替 print()

建党伟业观后感

建党伟业观后感

人物很多,时间跨度很长,有很多画面都很感人,不过感慨最多的是,是在一大会议开始时,陈公博携夫人一起到会的镜头。参加这样的秘密集会,本应该是谨慎隐秘的行动,却将妻子带着,就像去游山玩水,实在证明其不够上心,也无怪乎其后来投敌叛党。另外周佛海在开会期间,也牵扯进跟一位富家小姐关系暧昧的事件,最终导致其后来跟那位小姐私奔去日本,并逐渐远离了党的活动。由此可见,开会期间绝不能带老婆参加,否则就会像陈公博、周佛海那样成为叛徒。

感慨到了这里或许本该就结束了,但是又想到另外一个情节,就是在嘉兴南湖,李达的妻子王会悟坐在船头那个美景,那个画面太美了。而且一大会议中关于住宿等问题,都是王会悟帮着李达张罗的。所以这样看来,携妻子开会本身没有必然说就是坏事,关键还是在于开会的时候妻子是帮正忙还是帮倒忙,而更关键的,还是在于那个开会的人本身。

历史已经远去了,很多细节都已经模糊了,但留给我们记忆的,却并没有减少。所谓暗淡了刀光剑影,远去了鼓角争鸣,一个个鲜活的面孔,却永远留在我们心中。