0

I have a link in a django html template. I want to pass in a slugified string to the view for processing. I am getting an error and it is no slugifying the string. here is the code I have. Am I missing something or do i need to add something for slugify to work on the string...

<p><a href="{% url 'group_home' group.group.name|slugify %}">{{ group.group.name }}</a></p>

url:

url(r'^(?P<groupname>[\w+]+)/$', views.group_home, name='group_home'),

string example:

first group

here is the error:

NoReverseMatch at /groups/
Reverse for 'group_home' with arguments '('first-group',)' not found. 1 pattern(s) tried: ['groups/(?P<groupname>[\\w+]+)/$']

Another question I have is how do i unslugify a string once I am in the view.

Omar Jandali
  • 814
  • 3
  • 20
  • 52

1 Answers1

1

You're missing a hyphen on your regex. It will match the hyphens of your slugified string:

url(r'^(?P<groupname>[\w+-]+)/$', views.group_home, name='group_home'),

Why would you want to "unslugify"? Maybe you're looking for something like a built-in class-based generic view. They allow you to retrieve an object based on the pk/slug specified in the url.

luvejo
  • 347
  • 2
  • 9
  • because the name in the database has spaces which is why when i filter the group object out i can filter it with spaces but you solution got it working – Omar Jandali Nov 21 '17 at 06:31