Django: 'module' object has no attribute 'index'

前端 未结 3 606
灰色年华
灰色年华 2021-01-02 23:24

I\'ve been trying to learn Django for the past few days, but recently I\'ve stumbled upon a problem I can\'t seem to fix. After finishing Django\'s own tutorial on writing y

相关标签:
3条回答
  • 2021-01-02 23:33

    Either do this :

    from lru.views import *
    
    urlpatterns = patterns(
        '',
        url(r'^$', index, name='index')
    )
    

    or

    from lru import views
    
    urlpatterns = patterns(
        '',
        url(r'^$', 'views.index', name='index')
    )
    

    I hope this helps.

    0 讨论(0)
  • 2021-01-02 23:37

    The second argument of url() should be string, anway I would change the lru/urls.py to:

    from django.conf.urls import patterns, url
    
    urlpatterns = patterns('',
        url(r'^$', 'lru.views.index', name='lru-index')
    )
    

    Hope it helps!

    0 讨论(0)
  • 2021-01-02 23:50

    Import the urls.py module into your view. like this;

    from django.http import HttpResponse
    from . import urls
    
    def index(request):
        return HttpResponse("Hello, world. You're at the poll index.")
    
    0 讨论(0)
提交回复
热议问题