views:

76

answers:

1

Where do I put python files to be redirected to by urls.py in Django? The tutorial showed something like this:

urlpatterns = patterns('', (r'^polls/$', 'mysite.polls.views.index'),

Where do I set up pages to be easily linked as something.something.page like this? I am currently just trying to drop straight .py files in random directories and typing the name of the file in the urls.py file like so:

urlpatterns = patterns('', (r'file', 'file.py'),

Which is obviously not the correct way to do it. How do I create pages to be linked to in urls.py? Thanks.

+5  A: 

You need to use views. You can create views (keep reading the official django documentation), then import them into your urls.py file and use them. Here's an example:

views.py

from django.shortcuts import render_to_response

def index(request):
   """
   Main page.
   """
   return render_to_response('index.html') # display index.html

urls.py

from myproject.views import index
urlpatterns = patterns('',
   (r'^$', index),
)

This example will display your index.html page whenever you visit the root of your website (eg: /).

b14ck