简体   繁体   English

视图中没有功能的Django URL

[英]Django URLs without function in views

I tried to make a multi-upload system. 我试图制作一个多上传系统。 I have a functionnal page music.html, which list all musics and have some buttons to access to another page to add music. 我有一个功能性的页面music.html,其中列出了所有音乐,并且具有一些按钮可以访问另一个页面以添加音乐。

'Add Music' should be the button's name instead of 'Music'. 按钮的名称应为“添加音乐”,而不是“音乐”。

music.html : music.html:

<legend class="scheduler-border"><a href="{% url 'webgui.views.addmusic' %}" style="margin-bottom: 3px" type="button" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-plus"></span></a> Add Music </legend>

However, I don't need to execute any functions from music.html to addmusic.html... 但是,我不需要执行从music.html到addmusic.html的任何功能...

My urls.py : 我的urls.py:

url(r'^music/$','webgui.views.music'),
url(r'^addmusic/$','webgui.views.addmusic'),
url(r'^addmusic/add/$', 'webgui.views.multiple_uploader'),

Is there a way to redirect music.html to addmusic.html without executing 'webgui.views.addmusic' ?? 有没有一种方法可以将music.html重定向到addmusic.html而不执行'webgui.views.addmusic'? Really, I just need to display the form. 真的,我只需要显示表格。

EDIT : 编辑:

Yes, finally it works with my addmusic function in views.py : 是的,终于可以在views.py中使用我的addmusic函数了:

def addmusic(request):
return render(request, 'addmusic.html')

So it means an URL necessarily have a corresponding function ?? 因此,这意味着URL必然具有相应的功能? I can't pass "href=addmusic.html" in my template ? 我无法在模板中传递“ href = addmusic.html”吗? Just to know ... 想知道 ...

You can use TemplateView . 您可以使用TemplateView

from django.views.generic import TemplateView

    url(r'^addmusic/$', TemplateView.as_view(template_name="addmusic.html"), name='add-muusic'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM