Django Apache2 配置


在配置Django 与Apache2 过程中遇到的问题,以及总结的解决方案

Bug#1 attempt to write a readonly 


原因:放sqlite.db的文件夹及文件,没有访问权限。
解决方案: sudo chown www-data. sqlite.db


Bug#2 Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
原因: Apache2 没有开启rewrite 模块
解决方案: sudo a2enmod rewrite


Bug#3 attempt to make remote request from mod_rewrite without proxy enabled
解决方案:
Step1: sudo a2enmod proxy    //开启带来模块
Step2: sudo a2enmod proxy_http  //开启代理子模块


Bug#4 wap 站点下无法下载.dtp, .dwp文件


解决方案:
Step1: 在/etc/mime.type 文件中,添加如下两行:
application/zip dtp
application/zip dwp


Step2:在/etc/apache2/mods-available/mime.conf 文件中,添加如下两行
AddType application/zip .dtp
AddType application/zip .dwp


Step3: sudo service apache2 restart


Bug#5 上传文件没有写权限:Errno 13 Permission denied: media folder 
解决方案:
When you use runserver, the process is running as your normal user; and this user has access to /home/username/ to create folders and files.


When you run it under Apache, then the code is running as the apache process - typically www-data, and that user doesn't have access to create folders under your home directory.


The solution is not to chmod 777 even though this works. There are two better ways to approach this:


1.For production use, change the file paths to a directory where the www-data user normally has rights; and this should not be your home directory.


2. If you must use a location under your home directory; create a new path and set its parent's owner to www-data:www-data. This will allow it to work without giving the blanket 777 permissions.


Step1: sudo chown www-data. skins


Bug#6 Django调用bash 脚本, bash脚本里面调用了一个aapt工具,在~/.bashrc环境变量里面配置着, 当前用户可以访问,但是对于apache的www-data 用户或是sudo 用户都不能访问.
解决方案:把aapt工具放入系统/bin 目录下面,赋予777权限即可。


Bug#7 UnicodeDecodeError: 'ascii' codec can't decode byte 0x8f in position 1: ordinal
not in range(128)


当在python中拼接类似这样的字符串时:params= '%s/compress.sh "%s" "%s" "%s" "%s" "%s" "%s" "%s"' %(pathPrefix, source_path,
            output_path, settings.THEME_CONFIG_PATH, skin, skin_id, skin_version, skin_compatibility)
可能就会遇到,原因在于这些变量的编码不统一。


解决方案: Step1: 打印出所有变量的类型
        print type(pathPrefix)
        print type(source_path)
        print type(output_path)        
        print type(settings.THEME_CONFIG_PATH)
        print type(skin)  
        print type(skin_id)
        print type(skin_version)  
        print type(skin_compatibility)
   Step2:然后把相应的变量都转换为统一的格式,如str类型。
        pathPrefix = settings.EXEC_PATH_PREFIX.encode('utf-8')
        source_path = source_path.encode('utf-8')
   Step3: 一切就OK了。
备注:python的str, unicode对象的encode和decode方法。
python中的str对象其实就是"8-bit string",字节字符串, 等同与java中的byte[]
python中的unicode对象等同与Java中的String对象,或者java 的char[]
s="不错"
u=u"不错"
s.decode('utf-8') ---> 将str转换成unicode, 这和unicode(s, encodename)等同。
u.encode('utf-8') ---> 将unicode转换成str。参数指定使用的编码方式。


注意:python中默认编码格式是ascii




PS:Apache2 中,启动某个配置时,使用a2ensite skin.config
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值