最近要将django部署在godaddy上,当对注册的用户进行邮箱验证时,却遇到了很多问题,折腾了几天,今天终于搞定,特记录。
1、在setting中要设置成EMAIL_HOST = 'relay-hosting.secureserver.net',而不要用godaddy给的smtpout.secureserver.net,端口25.
2、在django.contrib.auth.forms.save函数最后,send_mail(_("Password reset on %s") % site_name,t.render(Context(c)), from_email, [user.email]),
此处site_name是xxxx.com,必须将.com去掉,否则虽然django显示发送成功,但其实接受方并没有收到。
3、在password_reset时,urls中需要设置4个
(r'^password/reset/$','django.contrib.auth.views.password_reset',{'template_name':'password_reset.html','email_template_name':'password_reset_email.html'}),
(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$','django.contrib.auth.views.password_reset_confirm',{'template_name':'password_reset_email.html'}),
(r'^password/reset/done/$','django.contrib.auth.views.password_reset_done',{'template_name':'password_reset_done.html'}),
4、godaddy是默认不安装django的,我们可以利用ssh,virtualenv在godaddy上建立一个django独立的环境,注意godaddy是不允许编译安装的,可以再自己电脑上先编译好了,再放在godaddy上,注意python的版本一致,否则会出错。
5、部署django我用的fastcgi,在html目录,新建一个.htaccess文件,内容如下:
AddHandler fcgi-script .fcgi
Options ExecCGI
Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^site_static/(.*)$ brainico/static/$1 [L]
RewriteRule ^brainico/static/(.*)$ - [L]
RewriteRule ^site_media/(.*)$ brainico/media/$1 [L]
RewriteRule ^brainico/media/(.*)$ - [L]
RewriteRule ^admin_media/(.*)$ - [L]
RewriteCond %{REQUEST_URI} !(brainico.cgi)
RewriteRule ^(.*)$ /brainico.cgi/$1 [QSA,L]
6、然后新建一个brainico.cgi文件(brainico是我的域名)
内容如下
#!/var/chroot/home/content/05/9608405/ENV/bin/python
import os, sys
sys.path.insert(0, "/var/chroot/home/content/05/9608405/html/")
sys.path.append("/var/chroot/home/content/05/9608405/html/brainico/")
os.chdir("/var/chroot/home/content/05/9608405/html/brainico/")
os.environ['DJANGO_SETTINGS_MODULE'] = "brainico.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
7、django的auth默认是通过username认证的,为了用email认证,加了一个backend,且将auth.models.User的__unicode__改为了self.first_name+self.last_name
总体来说,godaddy还是很强大的,他的SSH用着很方便,但似乎在技术上不思进取,python还只是2.4版本,什么web框架也没有,如果没有virtualenv,很难部署上。
8、godday自带了python还自带了virtualenv,有了ENV这样一个独立的环境,安装软件就很方便了。PIL不支持jgp格式文件,