89👍
I had the same problem.
It turns out I was confused because of the multiple directories named “mysite”.
I wrongly created a urls.py file in the root “mysite” directory (which contains “manage.py”), then pasted in the code from the website.
To correct it I deleted this file, went into the mysite/mysite directory (which contains “settings.py”), modified the existing “urls.py” file, and replaced the code with the tutorial code.
In a nutshell, make sure your urls.py file is in the right directory.
9👍
Django unable to resolve 127.0.0.1:8000/polls
because url config defined as r'^polls/'
.
Usual workaround:
mySite/urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^polls/', include('polls.urls')),
)
Note:
Whenever Django encounters include(), It chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf
for further processing.
mySite/polls/urls.py:
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('polls.views',
url(r'^$', 'index', name='index'),
)
Note: Instead of typing that out for each entry in urlpatterns, you can use the first argument to the patterns() function to specify a prefix to apply to each view function.
Answer If
If you want to access 127.0.0.1:8000/polls
Note: without trailing slash
use view based url
url(r'^polls', 'polls.views.index', name='index'),
So now you can access 127.0.0.1:8000/polls
without trailing slash.
- [Django]-"Too many SQL variables" error in django with sqlite3
- [Django]-How do I return a 401 Unauthorized in Django?
- [Django]-Why use Django on Google App Engine?
5👍
You’re accessing to http://yourdomain.com/, and you don’t have any URL defined for “/”.
You have two options:
-
If you want to access to the index page of your polls application you have to enter the URL: yourdomain.com/polls
-
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')), )
- [Django]-Django equivalent of SQL not in
- [Django]-Django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. (django 2.0.1)(Python 3.6)
- [Django]-Django npm and node packages architecture
5👍
To make the answer clear for beginners who has this issue by following the tutorial, the project root URLconf is the one in the same folder as settings.py which is:
mysite/mysite/urls.py
Just make sure import ‘include’. The code looks like:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^polls/', include('polls.urls')),
]
So in
mysite/mysite/settings.py:
The line should be:
ROOT_URLCONF = 'mysite.urls'
You don’t need create a fresh new root URLconf.
- [Django]-Dirty fields in django
- [Django]-How to save pillow image object to Django ImageField?
- [Django]-How to use subquery in django?
1👍
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
- [Django]-Actions triggered by field change in Django
- [Django]-Django FileField: How to return filename only (in template)
- [Django]-Django rest-auth allauth registration with email, first and last name, and without username
1👍
You put the urls.py folder into the outer MySite folder, you are suppose to put it in the inner one so its not mySite/urls.py, but mySite/mySite/urls.py:
ran into the same mistake when i did the tutorial
- [Django]-Removing help_text from Django UserCreateForm
- [Django]-How to backup a django db
- [Django]-Can to_representation() in Django Rest Framework access the normal fields
1👍
Another way to access 127.0.0.1:8000/polls
would be to redirect the browser when accessing 127.0.0.1:8000
. It is done by editing .../mysite/mysite/urls.py
as follows:
from django.conf.urls import include, url
from django.contrib import admin
from polls import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^polls/', include('polls.urls', namespace='polls')),
url(r'^$', views.index, name='index'),
]
- [Django]-Loading fixtures in django unit tests
- [Django]-Django : Filter query based on custom function
- [Django]-How to remove all of the data in a table using Django
1👍
Page not found?
If you get an error page here, check that you’re going to http://localhost:8000/polls/ and not http://localhost:8000/.
Source : https://docs.djangoproject.com/en/3.0/intro/tutorial01/
- [Django]-RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated
- [Django]-How can I use Django OAuth Toolkit with Python Social Auth?
- [Django]-Django cannot import name x
0👍
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.
- [Django]-Django: Equivalent of "select [column name] from [tablename]"
- [Django]-Is it possible to use FastAPI with Django?
- [Django]-Postgresql DROP TABLE doesn't work
0👍
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.
- [Django]-Dropdown in Django Model
- [Django]-How to make Facebook Login possible in Django app ?
- [Django]-What's the difference between ContentType and MimeType?
0👍
Add the below line in your Mysite/urls.py
url(r'^$', views.index, name='index'),
and check. If you have created your project correctly, it should work. Else something like above might have happened to have more than one files so confused.
- [Django]-Best way to make Django's login_required the default
- [Django]-Django Queryset with filtering on reverse foreign key
- [Django]-Django debug display all variables of a page
0👍
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
- [Django]-Django Rest Framework POST Update if existing or create
- [Django]-Difference between 'related_name' and 'related_query_name' attributes in Django?
- [Django]-Pass request context to serializer from Viewset in Django Rest Framework
0👍
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
- [Django]-Django middleware difference between process_request and process_view
- [Django]-Django development server, how to stop it when it run in background?
- [Django]-How to write setup.py to include a Git repository as a dependency