繁体   English   中英

django-'function'对象没有属性'resolve'

[英]django - 'function' object has no attribute 'resolve'

我试图学习一般基于类的视图和django。 该项目为notes_project ,在其中创建了一个应用notes 以下是这两个文件的urls.pynotes应用程序的views.py

notes_project / urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
import notes


urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'notes_project.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^notes/', include('notes.urls')),
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

笔记/ urls.py

from django.conf.urls import include, patterns, url
from .views import IndexView


urlpatterns = patterns(r'^$/', IndexView.as_view())

笔记/ views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import View


class IndexView(View):

    def get(request):
        return HttpResponse("Welcome to notes index")

但是,每当我访问URL http://127.0.0.1:8000/notes/时 ,我都会不断收到以下错误消息:

Request Method: GET
Request URL:    http://127.0.0.1:8000/notes/
Django Version: 1.7.4
Exception Type: AttributeError
Exception Value:    
'function' object has no attribute 'resolve'
Exception Location: /path/notes/venv/lib/python3.4/site-packages/django/core/urlresolvers.py in resolve, line 345
Python Executable:  /path/notes/venv/bin/python
Python Version: 3.4.2
Python Path:    
['/path/notes/notes_project',
 '/path/notes/venv/lib/python3.4',
 '/path/notes/venv/lib/python3.4/plat-x86_64-linux-gnu',
 '/path/notes/venv/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/path/notes/venv/lib/python3.4/site-packages']

patterns的第一个参数是一个字符串,充当其余模式的前缀。 同样,每个模式都必须是其自己的元组。 您已经在主要的urls.py中正确地做到了这一点,但是在注释一中却错过了。 它应该是:

urlpatterns = patterns('',
    (r'^$', IndexView.as_view()),
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM