You are not logged in.

Change Language:

Profile for Mapiga

Name Mapiga
Email Address n/a
Posts2
  • url.py is driving me crazy !
    Board » Django » Templates
    Hi,

    I'm knew to django. I have set up an app to display pages (with a title, subtitle, content and tags).
    I have followed the django polls tutorial and adapted it to suit my needs : Pages app.

    the admin part of the site is working well.

    here is the pages/view.py :

    from django.shortcuts import render_to_response
    from myapp.pages.models import Page
    from django.http import Http404

    def index(request):
    latest_page_list = Page.objects.all().order_by('title')[:5]
    return render_to_response('pages/index.html', {'latest_page_list': latest_page_list})

    def detail(request, page_title):
    try:
    p = Page.objects.get(pk=page_title)
    except Page.DoesNotExist:
    raise Http404
    return render_to_response('pages/detail.html', {'page': p})


    pages/url.py :

    from django.conf.urls.defaults import *

    urlpatterns = patterns('myapp.pages.views',
    (r'^$', 'index'),
    (r'^pages(?P<page_title>)/$', 'detail'),
    )

    templates/pages/index.html

    {% if latest_page_list %}
    <ul>
    {% for page in latest_page_list %}
    <li><a href="/pages/{{ page.title }}">{{ page.title }}</a></li>
    {% endfor %}
    </ul>
    {% else %}
    <p>No page are available.</p>
    {% endif %}


    html outpout exemple:

    <ul>

    <li><a href="/pages/Test">Test</a></li>

    </ul>



    My problem is that I cant access to other pages than pages/index.html wich is basically a list of link of all the page entries.
    When I hit the link in the list, it should leads to detail.html template, this is the message Django gives me :


    Page not found (404)
    Request Method: GET
    Request URL: http://127.0.0.1:8000/pages/Test

    Using the URLconf defined in myapp.urls, Django tried these URL patterns, in this order:

    1. ^admin/
    2. ^pages/ ^$
    3. ^pages/ ^pages(?P<page_title>)/$

    The current URL, pages/Test, didn't match any of these.

    I have a file named detail.html in the templates/pages folder, with a simple html outpout to show the title of the page

    This is driving me nuts, I've been googling like hell to find answers or to look how others were doing, i've tried different syntax, but I still get to this fact that I haven't found an answer, meanings that I probably made a beginner mystake, so I apologize if for some of you the answer is obvious.

    thx if anyone can help


    --- Dernière modification par Mapiga le 2010-05-24 11:01:02 ---


Powered by Sphene Community Tools