此代码在默认登录模板中:
{{ form.errors }}
Run Code Online (Sandbox Code Playgroud)
帐户处于非活动状态时生成此html输出:
<ul class="errorlist">
<li>__all__
<ul class="errorlist">
<li>This account is inactive.</li>
</ul>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
为什么要打印字符串_ all _?
顺便说一句,我正在使用开发版本.
这是我在nginx上的"内部"设置:
location /issues/ {
root /home/some_user/some_project/;
internal;
}
Run Code Online (Sandbox Code Playgroud)
当我注释掉"内部"部分时,Nginx在"issue"文件夹中提供文件,其中的文件就可以了.但即使启用它,我仍然无法提供Python或PHP代码中的任何文件:
# Python, outputs an empty zip
import os
file_name = '12.pdf.zip'
response = HttpResponse()
response['Content-Disposition'] = 'attachment; filename=%s' % t_str(file_name)
response['Content-Length'] = os.path.getsize(file_path)
response['Content-Type'] = "application/zip"
response['X-Accel-Redirect'] = '12.pdf.zip'
return response
# PHP, does nothing
header("X-Accel-Redirect: 12.pdf.zip");
Run Code Online (Sandbox Code Playgroud)
这些是启用站点/默认和nginx.conf.8000代表Django,81代表PHP
server {
listen 80; ## listen for ipv4
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
# proxy / requests to apache running django on port 8081
proxy_pass http://127.0.0.1:8000/;
proxy_redirect off;
proxy_set_header Host $host; …Run Code Online (Sandbox Code Playgroud) 我需要将Django Queryset对象转换为Json字符串.内置的Django Serialization库非常有用.虽然它从创建它的位置指定模型的名称.既然我不需要这个,我怎么摆脱它呢?我还需要覆盖什么才能使用下面重写的end_object方法?
class Serializer(PythonSerializer):
def end_object(self, obj):
self.objects.append({
"model" : smart_unicode(obj._meta), # <-- I want to remove this
"pk" : smart_unicode(obj._get_pk_val(), strings_only=True),
"fields" : fields
})
self._current = None
Run Code Online (Sandbox Code Playgroud)