0

I just ran into a problem..

I'm trying to build a website at the moment with different pages. So I created a django app called pages, with the following fields:

  • title
  • text
  • URL

The idea is, that users can create new pages and delete existing ones and it actually affects the navigation in real time.

So in my urls.py I wanted to handle this somehow like this:

from django.conf.urls.defaults import *


urlpatterns = patterns('',
  (r'^pages/(/w)', pages.views.display_content),
)

For example there could be a page with URL property "page1", then "page1" should be stored by (/w) and passed over to pages.views.display_content, which then would display the corresponding data. The "page1" page would be accessible through domain.com/pages/page1.

However, as I'm not really good with regex, I think I really need your help. I would be really happy if someone could explain to me how I have to write my URL rule for this..

Good Night :)

0

1 Answer 1

1

In addition, you could name the parameter that will be captured and passed to your view function with this notation:

...
(r'^pages/(?P<page_name>\w+)', 'pages.views.display_content'),
...

So you can access it with that name in your view function. Its header should look like this:

def display_content(request, page_name):
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.