-1

i am learning django by using django 1.6 documents tutorial 1 - 6. this round is my 4th try and, previous 3 try was successful and i understand more on every try.

i am in tutorial 3 now, to create views.

according to the documents, after i created a view, i need to map it to a URL. so i follow the documents to add a urls.py in the polls directory. and then i follow the document to add include() to mysite/urls.py i am able to so called wired an index view into the polls view.

now if i go back to localhost:8000, i get an error page, so my question is 1) WHY? 2) how to get back my localhost:8080 index page co-exist with the polls index page?

thank you very much everyone for your time. i am new and sorry for so simple question. thank you.

updated: this is my urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^polls/', include('polls.urls')),
)

this is my polls/urls.py

from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index')
)

the error msg is:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
^polls/
The current URL, , didn't match any of these.
pinky
  • 382
  • 1
  • 5
  • 17
  • Post your **URLs.py**. We can't help you without code. – rnevius May 09 '14 at 04:02
  • You must post your traceback / exceptions, and relevant code. Your descriptions cannot be as descriptive as the actual error message and your actual code. – Yuji 'Tomita' Tomita May 09 '14 at 04:15
  • thank rnevius and yuji, please see my updated paste code of my urls.py and error msg. thank you. – pinky May 09 '14 at 05:48
  • ps, if i comment out url(r'^polls/', include('polls.urls')), i am able to show localhost:8000 with no error, the error occur after i add url(r'^polls/', include('polls.urls')), – pinky May 09 '14 at 05:51

1 Answers1

0

http://localhost:8000 index page will be displayed when you created a project (mysite). After creating an application and including it in installed apps in settings.py, you will no longer view the index page of the project, rather your admin page of the application (polls) will be visible at http://localhost:8000/admin

And if you had created any views with the following patterns in polls/urls.py

urlpatterns = patterns('',
       url(r'^$', views.index, name='index'),
       url(r'^blog/$', views.blog, name='blog'),
)

You need to visit http://localhost:8000/polls for your index page and http://localhost:8000/polls/blogs for your poll blogs page

Editing my answer for step by step approach:

create index.html at polls/templates/polls directory.

in polls/views.py

from django.shortcuts import render_to_response
def pollindex(request):
     return render_to_response('polls/index.html', context_instance=RequestContext(request))

in polls/urls.py

urlpatterns = patterns('',
      url(r'^index/$', views.pollsindex, name='index'),
)

in your project/urls.py

urlpatterns = patterns('',
     url(r'^polls/', include('polls.urls')),
     url(r'^admin/', include(admin.site.urls)),
)

And now you can view your template index.html at http://localhost:8000/polls/index

Ria
  • 225
  • 1
  • 7
  • 18
  • hi Ria, i think my concept is still old, but please bear with me, i hope my guest visiting localhost:8000/index.html and visit polls page via localhost:8000/polls/index.html, how should i config with the urls.py files? – pinky May 19 '14 at 06:31
  • I think you are confused with templates and its views. index.html should be a template at polls/templates/polls/ directory. And this template file needs to be fetched in a view, which should be mentioned in url. Check my edit for more info. – Ria May 22 '14 at 05:26