rwx
rwx

Reputation: 716

Slash before # when linking with href="#"

What does not work: If i create a link (e.g. on domain.tld/main) with href="#" i get the link displayed as domain.tld/main# and not as i wanted it to be as domain.tld/main/#. I want the consistency as it is displayed on my index page with no url subdirectory as domain.tld/#.

Configuration:

urls.py

urlpatterns = [

url(r'^$', views.UserLogin),

url(r'^logout$', 'django.contrib.auth.views.logout', {'next_page':'/'}),

url(r'^main$', views.Main),

]

views.py

def Main(request):
    if not request.user.is_authenticated():
         return HttpResponseRedirect("http://www.domain.tld")
    else:
         return render(request, "main")

Upvotes: 0

Views: 136

Answers (2)

chem1st
chem1st

Reputation: 1634

The way it works now is a default way. '#' sign is reserved in urls as the delimiter of a fragment identifier, so it does not point at a directory of a site and it is simply added to the current path.

The reason why it works as you expect in case of index page is the impossibility of changing your domain name - '#' cannot be directly added to www.domain.tld but only through a slash sign.

Upvotes: 1

Sayse
Sayse

Reputation: 43300

The only way you're really going to be able to have your intended slash is if you include it in the url all the time

url(r'^main/$', views.Main),

So thats a decision you'll have to make as to whether or not thats acceptable. #'s main purpose is only to scroll to the top of the page

You can read more about that in this question

Upvotes: 5

Related Questions