DisplayName
DisplayName

Reputation: 87

using pipe delimited string in URL in django

I am trying to pass a pipe delimited string as a parameter in my url in django, but it fails to route to the respective view.

This is my pipe delimited string:

"main/1|adel|1|1989-09-19|1|1|test alert|2018-03-16-09-26-00|test module|1|1|test encounter"

and this is my url pattern:

from django.conf.urls import url
from django.views.generic import RedirectView
from alerter import views

app_name = 'alerter'

urlpatterns = [

    url(r'^main/(?P<message>[a-zA-Z0-9_]+)/$',
    views.TheView.as_view({'get': 'view'}), name = 'main'),



]

Upvotes: 0

Views: 433

Answers (1)

Chris
Chris

Reputation: 137114

\w doesn't match |:

For Unicode (str) patterns:

Matches Unicode word characters; this includes most characters that can be part of a word in any language, as well as numbers and the underscore. If the ASCII flag is used, only [a-zA-Z0-9_] is matched (but the flag affects the entire regular expression, so in such cases using an explicit [a-zA-Z0-9_] may be a better choice).

Adjust your pattern, e.g. by capturing [a-zA-Z0-9_|]:

url(r'^main/(?P<message>[a-zA-Z0-9_|]+)/$',
    views.TheView.as_view({'get': 'view'}), name='main')

Upvotes: 1

Related Questions