1

let's base URL is so.com So, if URL start with abc e.g.

so.com/abc/
so.com/abc/123
so.com/abc?newtab=123
so.com/abc#123
so.com/abc/123?tab=new
...

Then all this URL patterns should go to a Class Abc

myapp/urls.py 
...
url(r'^abc[a-zA-Z0-9=#_\?\-/]+$',views.Abc.as_view(),name='abc')

myapp/myviews/abc.py

class Abc(View):
   def get(self,request):
    ...
   def foo(user_id):
   ...
   def bar(post_id):
   ...

In function get(self,request): how to get everything after abc that was requested . e.g.

so.com/abc/xyz => /xyz
so.com/abc#123 => 123
so.com/abc?tab=new => ?tab=new 
 so.com/abc/123?tab=new => tab = new and 123 

When #123 is added after abc then it automatic converts to abc/#123

How to get this work ?

I have seen many question but they are not helpful.

Django Get Absolute URL

What is a "slug" in Django?

How to get the current URL within a Django template?

...

Community
  • 1
  • 1
sonus21
  • 5,178
  • 2
  • 23
  • 48

1 Answers1

1

So, first, you cant get # parameter.That is not sent to the server, read more here

To parse so.com/abc/xyz => /xyz and so.com/abc?tab=new => ?tab=new

url(r'^abc/?$',views.Abc.as_view(),name='abc')
url(r'^abc/(?P<param>\w+)/?$',views.Abc.as_view(),name='abc')

class Abc(View):

    def get(self,request,param=None):
        print param # in param you get /xyz
        tab = request.GET["tab"] # here you get ?tab=new 
levi
  • 22,001
  • 7
  • 73
  • 74