简体   繁体   中英

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:

 <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

I know that django/server side does not know about the #/something , so how do I handle it in javascript or 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? If I figure that out, can I append the fragment in the http get request?

If it's still just a link, there's no reason not to append the fragment to the generated 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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