python – Django属性错误. ‘module’对象没有属性’rindex’

栏目: Python · 发布时间: 7年前

内容简介:http://stackoverflow.com/questions/7052578/django-attribute-error-module-object-has-no-attribute-rindex

我刚刚开始使用django,只在网络书的第3章.

当我尝试访问该网站时,我不断得到这个奇怪的错误.

/ test /

‘module’对象没有属性’rindex’

我的urls.py就是

from django.conf.urls.defaults import *
from mysite import hello
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
      ('^test/$',hello),
)

我的hello函数是mysite.

Python路径是

['/home/james/django/mysite', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0', '/home/james/django']

我真的不明白这里发生了什么.我假设我忽略了一些愚蠢的东西,因为它似乎很简单.当我从 python 解释器中的mysite import hello做的时候,它不会引起任何错误.

任何帮助都会很棒

编辑:

追溯

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/test/
Django Version: 1.2.3
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.co
 ntrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.messages']
    Installed Middleware:
    ('django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
  91.                         request.path_info)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in resolve
  217.                     sub_match = pattern.resolve(new_path)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in resolve
  123.             return self.callback, args, kwargs
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in _get_callback
  134.             mod_name, func_name = get_mod_func(self._callback_str)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in get_mod_func
  78.         dot = callback.rindex('.')

Exception Type: AttributeError at /test/
Exception Value: 'module' object has no attribute 'rindex'

你好函数是

from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world")

你可能需要改变

from mysite import hello

像一样

from mysite.hello_file import hello_view

然后使用:

('^test/$',hello_view)

因为你需要传递一个(view)函数,而不是一个文件或者模块.正如我认为mgalgs试图解释的那样,但是我觉得初学者有点不清楚.

http://stackoverflow.com/questions/7052578/django-attribute-error-module-object-has-no-attribute-rindex


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Google将带来什么?

Google将带来什么?

杰夫·贾维斯 / 陈庆新、赵艳峰、胡延平 / 中华工商联合出版社 / 2009-8 / 39.00元

《Google将带来什么?》是一本大胆探索、至关重要的书籍,追寻当今世界最紧迫问题的答案:Google将带来什么?在兼具预言、宣言、思想探险和生存手册性质的这样一《Google将带来什么?》里,互联网监督和博客先锋杰夫·贾维斯对Google这个历史上发展速度最快的公司进行了逆向工程研究,发现了40种直截了当、清晰易懂的管理与生存原则。与此同时,他还向我们阐明了互联网一代的新世界观:尽管它具有挑战性......一起来看看 《Google将带来什么?》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具