Page not found 404 on Django site?

前端 未结 13 2298
既然无缘
既然无缘 2020-12-14 00:46

I\'m following the tutorial on Django\'s site to create a simple poll app. However, Django is unable to resolve \"//127.0.0.1:8000/polls\" , even though I\'ve defined the re

相关标签:
13条回答
  • 2020-12-14 00:55

    i had the same issue and got it resolved by adding /polls after http://server:port/ and so final address in server looks like: http://server:port/polls

    0 讨论(0)
  • 2020-12-14 00:58

    You're accessing to http://yourdomain.com/, and you don't have any URL defined for "/".

    You have two options:

    1. If you want to access to the index page of your polls application you have to enter the URL: yourdomain.com/polls

    2. You can also modify you mySite/urls.py file to access from just yourdomain.com

      from django.conf.urls import patterns, include, url
      
      from django.contrib import admin
      urlpatterns = patterns('',
      
      url(r'^admin/', include(admin.site.urls)),
      
      url(r'^$', include('polls.urls')),
      
      )
      
    0 讨论(0)
  • 2020-12-14 00:58

    Depending on where you put your ROOT urls.py, you set your ROOT_URLCONFIG accordingly, if you have it in your outermost folder containing manage.py then "urls" is ok. if you have it in someother folder then you have to do ".urls"

    Credit for the answer to jerryh91

    For more info about how it works, check How Django processes a request

    0 讨论(0)
  • 2020-12-14 00:59

    In my case, it was a stupid mistake. I wanted to integrate the plugin django-tinymce, and test it. So following this guide, I did the step 3 and exported the variable to the path. As the server runned again, I received the not found error, showing the message:

    Using the URLconf defined in testtinymce.urls, Django tried these URL patterns, in this order: ....

    But I didn't know what exactly it was, until I remembered exporting the variable DJANGO_SETTINGS_MODULE

    running unset DJANGO_SETTINGS_MODULE in terminal solved my issue. Hope that it helps someone too.

    0 讨论(0)
  • 2020-12-14 01:04

    Actually the problem is that you didn't notice that mysite/urls.py and polls/urls.py are two different files and you modified polls/urls.py instead of putting mysite/urls.py in the urls.py file in ...mysite\mysite folder.

    0 讨论(0)
  • 2020-12-14 01:04

    2017-10-05_12:03 ~/mysite/mysite
    $ vi urls.py 2017-10-05_12:04 ~/mysite/mysite
    $ cd ../.. 2017-10-05_12:04 ~
    $ mv mysite SENSIBLE_NAME_DJANGO_ROOT

    0 讨论(0)
提交回复
热议问题