user1292656
user1292656

Reputation: 2560

Get module name as parameter in request

What is the best way to get my module name as a function paramteter (entity) in request function?. I tried the following but is not working at all (Page not found). Something is wrong in the url regex? :

url(r'^<entity>=accounts/(?P<pk>[0-9a-z\-]+)/activate_entity/$', activate_entity)

def activate_entity(request, entity, pk):

entity_model = apps.get_model(app_label='entities', model_name=entity)
entity_object = entity_model.objects.get(pk=pk)

Upvotes: 0

Views: 35

Answers (1)

JPG
JPG

Reputation: 88619

Your regex pattern is wrong. try the following

url(r'^(?P<entity>[a-zA-Z_]+)/(?P<pk>[0-9a-z\-]+)/activate_entity/$', activate_entity)

and the url will be, /{entity_name}/{pk}/activate_entity/

Upvotes: 1

Related Questions