1

I'm building a website with Django. I want to have a string url [already done], but I want the string to be changeable based on variables.

sudocode: variable a = "Hello"

url = "www.facebook.com/a" ----> I want the "a" to be changeable, so if it changes, the url goes to a different website.

What is the best way to do this?

thanks

1
  • 1
    url = "www.facebook.com/" + a ? Commented Jul 10, 2013 at 19:51

1 Answer 1

2

You should use saving groups in your urls.py:

from django.conf.urls import patterns, url

urlpatterns = patterns('',
    url(r'^(?P<part>\w*)/$', 'my_app.views.my_view'),
)

Then, in your my_view view the string will appear as a keyword argument:

def my_view(request, part=None):
    print part

Hope that helps.

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.