请帮我明星学习django。我试着理解为什么我得到404错误。
有我的主要urls.py
from django.conf.urls import include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('account_app.urls')),
]
我的帐户urls.py 来自django.conf.urls导入模式,url
from account_app import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
有我对accout的看法
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from yes_no.models import account_class # added to model yes_no
def index(request):
template = loader.get_template('./index.html')
context = RequestContext(request, {
'a' : a,
})
return HttpResponse(template.render(context))
P.S。我的index.html文件存在于accout view和urls file
的文件夹中感谢您的帮助。
答案 0 :(得分:0)
也许您需要开始使用Class Based View?一切都变得更加轻松。
urls.py应该是这样的
from django.conf import settings
from django.views.static import serve
from some_app.views import HomePageView(
urlpatterns = [
url(r'^about/', HomePageView(.as_view()),
]
if settings.DEBUG:
urlpatterns += [
url(r'^media/(?P<path>.*)$', serve, {
'document_root': settings.MEDIA_ROOT,
}),
]
views.py
from django.views.generic.base import TemplateView
class HomePageView(TemplateView):
template_name = "home.html"
def get(self, request, *args, **kwargs):
context = dict()
context['foo'] = 'bar'
return Homepage.render_to_response(self, context)
我们需要完整的跟踪错误