我得到了一个全球名称' RequestContext'我的django项目没有定义"错误。
请帮帮我..
这是我的代码。
home / views.py
import os
from django.shortcuts import render_to_response
def home(request):
return render_to_response('/home.html')
和项目urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import patterns, include, url
from django.contrib import admin
from home import views
admin.autodiscover()
urlpatterns = patterns( '',
url(r'^$', 'home.views.home', name='home'),
url(r'^admin/', include(admin.site.urls)),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
答案 0 :(得分:3)
您需要从django.template
导入RequestContextfrom django.template import RequestContext
return render_to_response('home.html', context_instance=RequestContext(request))
答案 1 :(得分:2)
只需将from django.template import RequestContext
导入您的view.py文件,然后将render_to_response
更改为
return render_to_response('/home.html', context_instance=RequestContext(request))