Search code examples
pythondjangourlmodels

Django - Appending model parameter to url


Let's suppose I have this model

class Example(models.Model):
    FirstName = models.CharField(max_length=100)
    LastName = models.CharField(max_length=100)

And wanted that after the user fills the model to redirect to an url with the format

localhost/FirstName-Lastname

What would I need to write in the urls.py file?


Solution

  • You will need an url like this:

    url(r'^(?P<first_name>\w+)-(?P<last_name>\w+)/$', views.your_view),
    

    You can see docs here