我似乎无权访问我的 django 模板中的请求对象。
这是我的 settings.py 文件的一部分:
import django.conf.global_settings as DEFAULT_SETTINGS
TEMPLATE_CONTEXT_PROCESSOR = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.request',
)
网址.py
urlpatterns = patterns('',
url(r'^event/create/$', EventCreateView.as_view(), name='create_event'),
url(r'^event/update/(?P<pk>\d+)/$', EventUpdateView.as_view(), name='update_event'),
url(r'^event/delete/(?P<pk>\d+)/$', EventDeleteView.as_view(), name='delete_event'),
)
视图.py
from django.views.generic import CreateView, UpdateView, DeleteView
from events.models import Event
from events.forms import EventForm
class EventCreateView(CreateView):
model = Event
form_class = EventForm
class EventUpdateView(UpdateView):
model = Event
form_class = EventForm
class EventDeleteView(DeleteView):
model = Event
表格.py
from django.forms import ModelForm
from events.models import Event
class EventForm(ModelForm):
class Meta:
model = Event
event_form.html(用于 CreateView/UpdateView)
{% block content %}
<form action='{{ request.get_full_path }}' method='post'>
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type='submit' value='Create event!' />
</form>
{% endblock %}
上面, request.session 似乎什么也没做。我试过查看文档和类似的问题,但似乎没有任何效果。有任何想法吗?
提前致谢。