I made a fresh install of django 1.6.2 in it's own virtualenv. No syncdb, no other configs. The only other apps installed are pip, setuptools and dojango. I followed the instructions in this wiki page https://github.com/klipstein/dojango/wiki/Gettingstarted
when I try 127.0.o.1:8000/dojango/test/ or localhost:8000/dojango/test I get
Page not found (404)
Request Method: GET
Request URL: http://127.0.o.1:8000/dojango/test/
Using the URLconf defined in dojango.urls, Django tried these URL patterns, in this order:
^dojango/ ^dojango/
The current URL, dojango/test/, didn't match any of these.
this is my INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dojo_tutor',
'dojango',)
and this is my urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^dojango/', include('dojango.urls')),
# url(r'^admin/', include(admin.site.urls)),
)
The wiki page says to use (r'^dojango/', include('dojango.urls')), but I tried both like that and url(r'^dojango/', include('dojango.urls')),. I still get 404
Ok, it was a silly mistake. Foolishly I had named my project dojango so naturally there was a naming conflict. Deleted the project and recreated it with another name. Now it works.
Related
I'm just getting started with Django, and I'm a touch rusty with web development, so this may be an easy one. I'm stepping through the Django Polls Tutorial from the official documentation and I encounter a problem nearly right away. I'm not having success accessing http://localhost:8000/polls/ . I receive the error...
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/polls/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls/, didn’t match any of these.
Here is my relevant code...
\mysite\polls\views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
\mysite\polls\urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
\mysite\urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
\mysite\mysite\setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
ROOT_URLCONF = 'mysite.urls'
Development server reads...
Not Found: /polls/
[06/Dec/2022 15:02:01] "GET /polls/ HTTP/1.1" 404 2095
I have tried a hodgepodge of fixes that I've seen from other similar tutorial fixes, but nothing has worked and I feel like I'm taking stabs in the dark at this point.
Thank you Hash & Carlos for taking a look.
I modified as suggested, and restarted server, but I get the exact same result...
\mysite\mysite\settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
]
I feel as though there is a simple path error occurring somehow. Could there have been an error in my django setup? I do see the spaceship at localhost:8000, as I should.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
]
you are written the code correclty but you need to add your apps in intalled apps in settings.py file
I deleted my project, and my virtual environment(ok because this was the only thing in it), and started over from scratch. This time I was successful. I'm not completely sure why. It is not clear to me where the problem was, but I am ok moving on to bigger and better challenges. Ty for your responses!
BTW: I did not have to add "polls" to the settings.py file, which is consistent with the tutorial
I'm new to Django and I'm following this tutorial: https://www.django-rest-framework.org/tutorial/1-serialization/
When I run the server with python manage.py runserver, it seems to work fine showing me no errors.
However when I visit http://127.0.0.1:8000/snippets/ it gives me the following error:
Using the URLconf defined in tutorial.urls, Django tried these URL patterns, in this order:
admin/
The current path, snippets/, didn’t match any of these.
Here's my urls.py located in the tutorial folder:
from django.urls import path, include
urlpatterns = [
path('', include('snippets.urls')),
]
I don't understand what's going on, how come it only checks admin/ if I'm wiring the root urlconf to snippets.urls?
On a related note, when I modify urls.py and add gibberish the server won't give me an error, however if I were to modify models.py then it'll start complaining, that's why I'm getting the feeling it doesn't even check my urls.py and maybe instead some default one...
Any tips are very appreciated!
EDIT:
Here's my urls.py located in the snippets folder:
from django.urls import path
from snippets import views
urlpatterns = [
path('snippets/', views.snippet_list),
path('snippets/<int:pk>/', views.snippet_detail),
]
In settings.py I've only modified the INSTALLED_APPS part with the two last apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'snippets.apps.SnippetsConfig',
]
Are you sure you don't have another instance of Django running?
That's the only thing I can think of since admin isn't even in your current urls
DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL: https://tehb123.pythonanywhere.com/admin/login/?next=/admin/
Django Version: 1.9.3
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /usr/local/lib/python3.5/dist-packages/django/db/models/query.py in get, line 387
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.5.1
Python Path:
['/var/www',
'.',
'',
'/home/tehb123/.local/lib/python3.5/site-packages',
'/var/www',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/tehb123/mysite']
Server time: Thu, 13 Oct 2016 05:34:55 +0000
urls
from django.conf.urls import url, patterns, include
from django.contrib import admin
from django.contrib.flatpages import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('Mysitez.urls')),
# url(r'^pages/', include('django.contrib.flatpages.urls')),
]
urlpatterns += [
url(r'^(?P<url>.*/)$', views.flatpage),
]
settings
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.templatetags',
'django.apps',
'django.contrib.sites',
'django.contrib.flatpages',
'Mysitez',
]
SITE_ID=1 in setting and all work, but why? not have idae =(
I found the solution in this other post:
"You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away:
'django.contrib.sites'
"
The admin site
once you create the project with django version > 1.6 , the admin site will enable django itself. but make sure you have following ["https://docs.djangoproject.com/en/1.10/ref/contrib/admin/"], once you create project , make python manage.py migrate then create the admin user using (python manage.py createsuperuser ). do the run command see the url like ("http://127.0.0.1:8000/admin/") you can see the login page
I've gone through the process, which is seemingly fairly straightforward of setting up an sitemap.xml file..
I'm getting 404 page when I go to www.example.com/sitemap.xml 'page not found' and a message (I've still got debug settings turned on..) along the lines of:
" Django tried these URL patterns, in this order:
^admin/
^nday/
^ ^$ [name='index']
^ ^tomorrow/$ [name='tomorrow']
^ ^day/(?P<day_name_url>\w+)/$ [name='day']
The current URL, sitemap.xml, didn't match any of these."
This is my urls.py file
from django.conf.urls import patterns, url
from django.contrib.sitemaps.views import sitemap
from nday import views
from nday import sitemap
from nday.sitemap import ndaySitemap
sitemaps = {
'posts': ndaySitemap,
}
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^tomorrow/$', views.tomorrow, name='tomorrow'),
url(r'^day/(?P<day_name_url>\w+)/$', views.day, name='day'),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),)
and my sitemap.py file..
from django.contrib.sitemaps import Sitemap
from nday import models
from nday.models import nationalday
class ndaySitemap(Sitemap):
changefreq = "daily"
priority = 0.5
def items(self):
return nationalday.objects.all()
I've installed sitemaps as per the settings.py file..
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
'nday',
)
Thank you so much in advance
If you are using the Django development server, it should reload when you make any code changes.
However in production (e.g. Apache or Nginx) you have to reload the server after making any changes to .py files.
I have created a new Django project where in I am able to access http://127.0.0.1:8000 but I can't access the admin dashboard http://127.0.0.1:8000/admin/.
INSTALLED APPS
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
#'django.contrib.sites',
'django.contrib.messages',
'health',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)
URLS
from django.conf.urls import patterns, include, url
from django.contrib import admin
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^$','authentication.views.login_authenticate'),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin_tools/', include('admin_tools.urls')),
)
Response
DoesNotExist at /admin/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.4.2
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /Library/Python/2.6/site-packages/django/db/models/query.py in get, line 366
Python Executable: /usr/bin/python
Python Version: 2.6.1
Python Path:
['/Users/iceman/Documents/onkar_workspace/MyProject',
'/Library/Python/2.6/site-packages/PyMySQL-0.5-py2.6.egg',
'/Library/Python/2.6/site-packages/elementtree-1.2.7_20070827_preview-py2.6.egg',
'/Library/Python/2.6/site-packages/Markdown-2.2.0-py2.6.egg',
'/Library/Python/2.6/site-packages/xhtml2pdf-0.0.4-py2.6.egg',
'/Library/Python/2.6/site-packages/pyPdf-1.13-py2.6.egg',
'/Library/Python/2.6/site-packages/pytz-2012c-py2.6.egg',
'/Library/Python/2.6/site-packages/django_bootstrap_toolkit-2.5.4-py2.6.egg',
'/Users/iceman/Documents/epicomm/PRHealth',
'/Users/iceman/Downloads/eclipse/plugins/org.python.pydev_2.7.0.2012110722/pysrc',
'/Library/Python/2.6/site-packages/ipython-0.13-py2.6.egg',
'/Library/Python/2.6/site-packages/icalendar-3.0.1b2-py2.6.egg',
'/Library/Python/2.6/site-packages/reportlab-2.5-py2.6-macosx-10.6-universal.egg',
'/Library/Python/2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.6-universal.egg',
'/Library/Python/2.6/site-packages/html5lib-0.95-py2.6.egg',
'/Library/Python/2.6/site-packages/django_timepiece-0.5.2-py2.6.egg',
'/Library/Python/2.6/site-packages/django_compressor-1.1.2-py2.6.egg',
'/Library/Python/2.6/site-packages/django_selectable-0.4.1-py2.6.egg',
'/Library/Python/2.6/site-packages/django_pagination-1.0.7-py2.6.egg',
'/Library/Python/2.6/site-packages/python_dateutil-1.5-py2.6.egg',
'/Library/Python/2.6/site-packages/distribute-0.6.28-py2.6.egg',
'/Library/Python/2.6/site-packages/MySQL_python-1.2.4b4-py2.6-macosx-10.6-universal.egg',
'/Users/iceman/Downloads/eclipse/plugins/org.python.pydev_2.7.0.2012110722/pysrc/pydev_sitecustomize',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/Library/Python/2.6/site-packages',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip']
You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away:
'django.contrib.sites'
You can also re-create the missing Site object from shell. Run python manage.py shell and then:
from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.xxx.com', name='xxx.com')
I guess this might help you.