重定向到页面
我面临一个问题:我想在我的更改表单中提供一个链接,该链接将重定向到一个页面,该页面可能是简单的 php 页面或任何页面,在该页面中我想执行一些数据库查询并显示它们。 我还想在点击时传递 id。 是否可以?
在我的 view.py 中我写道:
from django.shortcuts import render_to_response
from django.template import RequestContext
def MyClass(self,id,request):
return render_to_response('admin/custom_change_form.html')#my template location
我的模型和管理文件很简单。
I am facing a problem: I want to give a link in my change form that will redirect to a page which may be simple php page also or any page, in that page I want to perform some db queries and display them. I also wan to pass id on click. Is it possible?
In my view.py I wrote:
from django.shortcuts import render_to_response
from django.template import RequestContext
def MyClass(self,id,request):
return render_to_response('admin/custom_change_form.html')#my template location
My model and admin files are simple.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要直接发送到文件,请使用 direct_to_template()。 您可以在 url 中传递您喜欢的任何内容 - 只需将信息提供给您的模板,然后将其写入 url 中即可。 毕竟,Django 不需要 url 助手。
我感觉无论你想要做什么都是一些可怕的黑客事情,如果在 Django 中完成这一切会更好。
To send to a file directly, use direct_to_template(). You can pass anything in the url that you like - just give the information to your template, and write it in the url. After all, Django doesn't require url helpers.
I sense that whatever you're trying to do is some god-awful hackish thing that would be much better served by doing it all in Django.
您将需要覆盖该模型的更改表单并显示您想要的任何内容。 但这是假设您正在谈论 Django 中的 contrib 管理员。
实际上,您没有提供足够的信息供任何人准确回答您的问题。
You will need to override your change form for that model and display whatever you would like. But that is making the assumption you are talking about the contrib admin within Django.
Realistically you have not provided sufficient information for anyone to accurately answer your question.