django-1.3在windows系统环境下的一个出错?'SafeUnicode' object has no attribute 'status_code'

发布于 2022-08-24 01:44:43 字数 3080 浏览 7 评论 0

此问题同时提交在http://www.oschina.net/question/56585...
http://segmentfault.com/question/2923...

1) 系统环境是:apache2.2+wsgi+mssql+python2.7+django1.3 , 配置完成后,能够正常访问到django-admin等应用

2) 在浏览器中访问http://127.0.0.1:8006/user_all/时的报错信息:

AttributeError at /user_all/

'SafeUnicode' object has no attribute 'status_code'

Request Method:     GET
Request URL:     http://127.0.0.1:8006/user_all/
Django Version:     1.3.1
Exception Type:     AttributeError
Exception Value:    

'SafeUnicode' object has no attribute 'status_code'

Exception Location:     C:\Python27\lib\site-packages\django\middleware\common.py in process_response, line 94
Python Executable:     C:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe
Python Version:     2.7.2
Python Path:    

['C:\\Python27\\lib\\site-packages\\pip-1.1-py2.7.egg',
 'C:\\WINDOWS\\system32\\python27.zip',
 'C:\\Python27\\Lib',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\Lib\\lib-tk',
 'C:\\Program Files\\Apache Software Foundation\\Apache2.2',
 'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\bin',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\win32',
 'C:\\Python27\\lib\\site-packages\\win32\\lib',
 'C:\\Python27\\lib\\site-packages\\Pythonwin',
 'D:/wind1/']

Server time:     星期四, 5 七月 2012 17:06:52 +0800

3) settings的数据库配置:(数据库引擎采用的是django-mssql)

DATABASES = {
    'default': {
        ###'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'ENGINE': 'sqlserver_ado',
        'NAME': 'django',                      # Or path to database file if using sqlite3.
        'USER': 'django',                      # Not used with sqlite3.
        'PASSWORD': 'django',                  # 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.
    }
}

4) urls中的URL映射:

url(r'user_all/$', 'mysite.polls.views.django_user_all'),

5) views中的视图函数:

def django_user_all(request):
    from django.contrib.auth.models import User
    entry_list = User.objects.values()[0].all()
    html = "<html><head></head><body> {%for tmp in entry_list%} {{tmp}}  {%endfor%}
</body></html>"
    t = Template(html)
    c = Context(entry_list)

    return t.render(c)

6) 希望大家指出问题所在。谢谢了

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛装女皇 2022-08-31 01:44:43

这是在初学时因为时间和临时的工作任务影响,只做了一半,没有检查结果,过了N多天后,重新拾起来,发现的错误.现修正如下:

def django_user_all(request):
    from django.contrib.auth.models import User
    entry_list = User.objects.all()
    html = []
    for tmp in entry_list:
        html.append('<tr><td>user:</td><td>%s</td></tr>' % tmp )
    output = ('<html><head><title>user_all</title></head><body><table>%s</table></body></html>' % '\n'.join(html))
    return HttpResponse(output)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文