user502039
user502039

Reputation:

What is a regex in django for the following url?

What is a regex in django for the following url? It should run the view when it's on this page: http://localhost:8000/

Upvotes: 0

Views: 178

Answers (3)

Josh Smeaton
Josh Smeaton

Reputation: 48730

url(r'^/$', 'index', name='index')

Upvotes: 0

photoionized
photoionized

Reputation: 5232

The correct regex would be:

r'^$'

It should match when you hit either localhost:8000 or localhost:8000/

the ^ character means "at the start of the line,", the $ character means "at the end of the line." So basically this regex says something like, "when the absolute path to the resource is blank (i.e. you are at the root of the server) then return this view."

Upvotes: 3

tallowen
tallowen

Reputation: 4328

I think you are looking for something like this:

urlpatterns = patterns('views',
    (r'^$', '{{insert your view name here}}'),
)

Check out this documentation here: http://docs.djangoproject.com/en/dev/topics/http/urls/

Upvotes: 0

Related Questions