The current URL, app/, didn't match any of these

前端 未结 8 654
無奈伤痛
無奈伤痛 2020-12-17 17:58

I\'m a newbie in Django and just started looking at it before a day by installing Django 1.10 on my local.

I\'ve followed all the instructions of this link https://d

相关标签:
8条回答
  • 2020-12-17 18:34

    change the mysite/url

        from django.conf.urls import patterns,include, url
        from django.contrib import admin
    
        urlpatterns = patterns('',
        url(r'^&', include('polls.urls')),
        url(r'^admin/', include(admin.site.urls)),
        )
    

    Then run your server and visit 127.0.0.1/8000. This should take you to the index of ur website.

    or you leave your code as it is and run 127.0.0.1/8000/polls on your browser

    0 讨论(0)
  • 2020-12-17 18:39

    I think you have edited the wrong file when trying to change the root url config.

    Make sure you are editing the root url config in mysite/mysite/urls.py (the directory containing settings.py) not mysite/urls.py (the directory containing manage.py).

    As general advice, install the latest release, currently 1.9. Don't use 1.10, which is under development. Make sure that you are following the tutorial for 1.9, because the tutorial changes for different versions. For example, your mysite/urls.py doesn't match the tutorial for 1.9, as the urlpatterns should be:

    urlpatterns = [
        url(r'^polls/', include('polls.urls')),
        url(r'^admin/', admin.site.urls),
    ]
    
    0 讨论(0)
  • 2020-12-17 18:41

    I too had same problem going through the official docs tutorial. I was using cloud 9. What I realised before I was able to solve this problem was that while creating the workspace I already chose django(ie by the time my workspace was created, django had already been installed) And going through the tutorial, I again executed $ django-admin startproject mysite thereby having another layer of django with multiple directories and unavoidably the confusion. My solution was to delete everything and start all over.

    Since this problem is common to many people, I suggest that django tutorial docs should be more explicit on this.

    I hope this help somebody.

    0 讨论(0)
  • 2020-12-17 18:42

    if @Alasdair answer does not work, and it seems your working on correct files, just restart your server

    0 讨论(0)
  • 2020-12-17 18:46

    It's working. Go to your url bar and type your app name:

    http://127.0.0.1:8000/home
    

    My app name is home. It will work.

    If you want to set your app as your default page then import views from your app.

    Like

    from home import views
    

    then write

    url(r'^$', views.index),
    

    inside.

    It will set the views as your default page

    http://127.0.0.1:8000/
    

    When you type this it will redirect to your views.

    0 讨论(0)
  • 2020-12-17 18:49

    In settings.py you have a setting name INSTALLED_APPS-

    Adds you app i.e. polls to it.

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        ....
        'polls',
    ]
    
    0 讨论(0)
提交回复
热议问题