Re: regular expression confusion

22 views
Skip to first unread message
Message has been deleted

James Schneider

unread,
Jan 19, 2016, 5:49:15 AM1/19/16
to django...@googlegroups.com
On Tue, Jan 19, 2016 at 2:30 AM, Xristos Xristoou <sax...@gmail.com> wrote:
hello,

i have a regular expression confusion error i cant work my app with together 2 and 3 line from my blog/urls if i work regardless that lines work fine
but i need together for my project.

my mysite/urls

url(r'^admin/', include(admin.site.urls)),
url(r'', include('blog.urls')),

The second line should probably be a r'^', rather than just an empty string.
 
my blog/urls

1  url(r'^$', views.index, name='index'),
2 url(r'^(?P<slug>[^\.]+)/$', views.view_post, name='view_post'),
3 url(r'^(?P<slug>[\w-]+)/$', views.view_category, name='view_category')

This is probably not a good URL strategy. Your view_category URL's overlap with your view_post URL's, which means that your view_category URL's will never work because [\w-]+ is contained within [^\.]+, which matches any character except for a \ and period, neither of which will ever be contained in a common slug format (used by view_category).

Wouldn't it be better and more obvious to namespace the URL's so that what you are matching is much more clear? Otherwise you'll have no way of telling a post apart from a category.
 
2  url(r'^post/(?P<slug>[^\.]+)/$', views.view_post, name='view_post'),
3 url(r'^category/(?P<slug>[\w-]+)/$', views.view_category, name='view_category')

-James
Message has been deleted

Xristos Xristoou

unread,
Jan 19, 2016, 6:02:33 AM1/19/16
to Django users
yeah but now must be change mt template tags ?
 
for example

my first template tags from the main page to the view page

<h2> <a href="{{movies.slug}}">{{movies.Title}}</a></h2> 

Xristos Xristoou

unread,
Jan 19, 2016, 6:32:04 AM1/19/16
to Django users
i find it thnx for the help
Reply all
Reply to author
Forward
0 new messages