将模型从 url 传递到 create_object 通用输入视图
我有多个模型想要为其创建通用输入。我的第一遍使用了两个单独的 url:
url(r'^create_actor/$, create_object, {'model': Actor, 'template_name': 'create.html', 'post_save_redirect': '/library/', 'extra_context': {'func': 'Create Actor'}, 'login_required': 'True'}),
url(r'^create_movie/$, create_object, {'model': Movie, 'template_name': 'create.html', 'post_save_redirect': '/library/', 'extra_context': {'func': 'Create Movie'}, 'login_required': 'True'}),
我认为将它们合并到一个语句中会更好。我不确定如何将变量从 url 传递到参数中,以便该行根据该变量动态选择模型。
I have multiple models that I want to create generic inputs for. My first pass used two separate urls:
url(r'^create_actor/$, create_object, {'model': Actor, 'template_name': 'create.html', 'post_save_redirect': '/library/', 'extra_context': {'func': 'Create Actor'}, 'login_required': 'True'}),
url(r'^create_movie/$, create_object, {'model': Movie, 'template_name': 'create.html', 'post_save_redirect': '/library/', 'extra_context': {'func': 'Create Movie'}, 'login_required': 'True'}),
I assume it would be much better to combine these into one statement. I'm not sure how to pass a variable from the url into the parameters such that the line would dynamically select the model based on the variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有尝试过这个,但是您可以使用变量来捕获 create_ 之后的值并将其自动发送到 create_object 视图:
您必须以 /create_Actor/ 而不是 /creat_actor/ 的形式访问此 url。我不知道如何让 extra_context 键起作用。
希望这有帮助。
I haven't tried this, but you can use a variable to capture the value after create_ and have it automatically sent to the create_object view:
You'll have to access this url as /create_Actor/ instead of /creat_actor/. I'm not sure how to get the extra_context key to work.
Hope this helps.