我正在调用此网址:
url(r'^new/(?P<gigi>\d+)/$', views.myview.as_view(), name='create'),
as
127.0.0.1:8000/new/33
这就是django debug所说的:
Funzione View Argomenti Parole chiave Nome URL
my_app.views.myview()
{'gigi': u'33'}
我试图在模板中插入:
{{request.path}} # return full url
{{request.GET.gigi}} # return nothing
视图正确地看到gigi为33,但是可以从模板内部看到gigi吗?
这是观点:
class SimpleCreateView(CreateView):
def form_valid(self, form):
mygigi=self.kwargs['gigi']
return super(SimpleCreateManView,self).form_valid(form)
答案 0 :(得分:1)
您可以在视图中获取gigi
参数,然后将其发送到context
中的视图:
def myview(request, gigi):
context = {'gigi': igigi}
...
编辑:
编辑后:
class SimpleCreateView(CreateView):
...
def get_context_data(self, **kwargs):
ctx = super(SimpleCreateView, self).get_context_data(**kwargs)
ctx.update({'gigi': self.kwargs['gigi']})
return ctx