Re: Django by Example blog Tutorial

56 views
Skip to first unread message

Tom Evans

unread,
Oct 3, 2012, 6:59:02 AM10/3/12
to django...@googlegroups.com
On Wed, Oct 3, 2012 at 8:14 AM, Tuss4 <tuss...@gmail.com> wrote:
> This is my first time posting in the Django user group. I've been following
> the following lightbird Django by Example tutorials. I've hit a snag while
> following the blog tutorial (http://lightbird.net/dbe/blog.html). The thing
> is my comment link [code]
>
> <div class="commentlink"><a href="{% url blog.views.post post.pk
> %}">Comments</a></div>
>
> [/code]
>
> is not linking to the individual post. I checked my views.py and urls.py
> against the tutorial source code packet and it matches, but upon clicking it
> just displays the front page again. When you look at the url however you can
> see the posts primary key in the adress, but all posts are displayed.
>
> I'm ready to provide any information as needed. Thank you in advance for
> your help.
>
> In short, my blog isn't linking to individual posts.
>

So the URL generated looks "correct", but when you click on it, it
instead displays a different page?

That sounds like the URL is getting routed to the incorrect view.
Check your urls.py, does the view that gets displayed match the URL
(even partially)? Django will stop processing the urls.py for a
request once it has found the first URL regular expression that
matches the current URL.

Eg, if your urls.py has these patterns in it:

""
"blogs/(?P<blog_id>\d+)"

and then you request "/blogs/5", then the first regexp will match, and
it will not look any further. To stop this, you should properly start
and terminate your regular expressions with '^' and '$', which mean
start and end of string respectively:

"^$"
"^blogs/(?P<blog_id>\d+)$"

Cheers

Tom

Tuss4

unread,
Oct 3, 2012, 1:45:31 PM10/3/12
to django...@googlegroups.com, teva...@googlemail.com
Thank you for your prompt response. I'll try out your edit. This is what my urlsl.py (in the blog folder) looks like:

urlpatterns = patterns('blog.views',
    url(r'^', 'main'),
    url(r'^(\d+)/$', 'post'),
    url(r'^add_comment/(\d+)/$', 'add_comment'),
)

Tuss4

unread,
Oct 3, 2012, 1:53:31 PM10/3/12
to django...@googlegroups.com, teva...@googlemail.com
Still no difference. I'm starting to take there's something going on with views.py.
Reply all
Reply to author
Forward
0 new messages