Reputation: 1485
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
Upvotes: 1
Views: 46
Reputation: 474241
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.
Upvotes: 2