简体   繁体   English

重定向后将片段追加到Django URL吗?

[英]Append fragment to a django URL after redirect?

I have a set of anchor element that call the same django view but should set a different tab active in the course-detail view in my application like this: 我有一组anchor元素,它们调用相同的django视图,但应在我的应用程序的course-detail视图中将不同的选项卡设置为活动状态,如下所示:

 <a href="{% url 'courses:course-detail' course.id %}">Go to Exams</a>
 <a href="{% url 'courses:course-detail' course.id %}">Go to Lectures</a>
 <a href="{% url 'courses:course-detail' course.id %}">Go to Homework</a>
 <a href="{% url 'courses:course-detail' course.id %}">Go to Results</a>

In the course-detail view, an angular controller handles which tab is active, when clicked. 在课程详细信息视图中,角度控制器可控制单击哪个活动选项卡。 However, I want to be able to append the fragment (#/something) when user clicks the anchor elements above: 但是,当用户单击上面的锚元素时,我希望能够附加片段(#/某物):

For example when user clicks "Go to Results" the url should be /course/1/detail/#/results 例如,当用户单击“转到结果”时,网址应为/course/1/detail/#/results

I know that django/server side does not know about the #/something , so how do I handle it in javascript or angular? 我知道django / server端不知道#/something ,所以我该如何使用javascript或angular处理它?

I thought I could send an http get request from an angular controller when an anchor element is clicked but how do I get what the django view URL is? 我以为单击锚元素时可以从角度控制器发送http get请求,但是如何获取django视图URL是什么? If I figure that out, can I append the fragment in the http get request? 如果知道了,是否可以在http get请求中附加该片段?

If it's still just a link, there's no reason not to append the fragment to the generated URL. 如果仍然只是链接,则没有理由不将片段附加到生成的URL。

<a href="{% url 'courses:course-detail' course.id %}#/exams">Go to Exams</a>
<a href="{% url 'courses:course-detail' course.id %}#/lectures">Go to Lectures</a>
<a href="{% url 'courses:course-detail' course.id %}#/homework">Go to Homework</a>
<a href="{% url 'courses:course-detail' course.id %}#/results">Go to Results</a>

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

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