I am hosting my site at entworks.in
The site seems to be working fine until I try to get a 404 error like entworks.in/asdf <-- will give 404. After that when I try to load other pages, like entworks.in, it shows 404 for all pages.
Anyone has any idea what might be the problem? I am running it on nginx.
EDIT:
URLCONF
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
from haystack.forms import ModelSearchForm
from haystack.query import SearchQuerySet
from haystack.views import search_view_factory
import bootlog.views
from bootlog.views import BSearchView
urlpatterns = patterns('',
url(r'^about/', 'bootlog.views.profile_view', name='about'),
url(r'^e/', 'bootlog.views.engineering_view', name='engineering'),
url(r'^d/', 'bootlog.views.programming_view', name='programming'),
url(r'^s/',search_view_factory(
view_class=BSearchView,
template='bootlog/base.html',
searchqueryset = SearchQuerySet(),
form_class=ModelSearchForm
), name='haystack_search'),
url(r'^ckeditor/',include('ckeditor.urls')),
url(r'^$',bootlog.views.front_page_view),
url(r'^p/b(?P<blog_pk>\d+)p(?P<post_pk>\d+)/', bootlog.views.perma_post, name="blog-post"),
url(r'^rss/$', bootlog.views.LatestEntriesFeed(), ),
url(r'^all/',bootlog.views.html_render),
)
handler404='bootlog.views.view_404'
I am using gunicorn
EDIT 2: I was displaying the 404 page in wrong way. Hence the error. It was overwriting the main config.
Related
My django site is having web & mobile versions. I have enabled debug setting false which returns templates 404.html whenever the requested page is not found. I would like to modify the view function to return 2 different 404 html pages like 404.html/404mobile.html based on platform.
Detecting user browser through JavaScript in 404.html page did not help as my 404.html page has header and footer extends from base html file.
Modifying views will solve this? If so where is the debug setting class file residing in Django package?
Here is the function using user_agent ..
from user_agents import parse
def idfy(request):
user_agent = parse(ua_string)
if user_agent.is_mobile:
return HttpResponse('I m n mobile')
else:
return HttpResponse('I m n pc')
from django.conf.urls import patterns, include, url
from django.views.static import *
from django.conf import settings
from django.conf.urls.defaults import handler404
from app.views import error
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'app.views.home', name='home'),
)
handler404 = error.error_handler
overriding handler404 method resolves this issue
I've installed Django 1.6 and setup Gunicorn with Python 3.3. Everything works fine together as far as I can tell.
I'm trying to get a URL to look like this: web.com/piña. I've started an app with python3 manage.py startapp pina and created a super basic view.
# pina/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('¡Hola mundo! Esta es mi primera vista.')
I've also added a new URL entry like this.
# django_project/urls.py
from django.conf.urls import patterns, include, url
from pina import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^pi%C3%B1a/', views.index, name='index'),
)
But when I visit web.com/piña/, I get a 404 page.
The /admin/ URL works just fine. If I change r'^pi%C3%B1a/' to just r'^pina/', that also works—but that's a different word entirely.
i have installed DJANGO 1.5, once entered 127.0.01:8000 the beautiful HTLM page appears.
"it worked"
now whatever i enter in the Browser URL, it always goto default welcome page.
once i start playing with url.py this functionality get vanished. and i start getting 404 page.
is there any way to keep this functionality on i.e what ever is typed in the browser url it goes to main page exception for the defined url in url.py
please help
url.py
from django.conf.urls import patterns, include, url
from article.views import HelloTemplate
urlpatterns = patterns('',
url(r'^hello_template/$', 'article.views.hello_template'),
url(r'^hello_template_simple/$', 'article.views.hello_template_simple'),
other code snippet for "myproject/urls.py"
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import RedirectView
urlpatterns = patterns('',
(r'^myapp/', include('myproject.myapp.urls')),
(r'^$', RedirectView.as_view(url='/myapp/list/')),
(r'', 'myproject.myapp.views'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Just put a your default page as a catch-all URL at the end of the other URLs:
urlpatterns = patterns('',
url(r'^hello_template_simple/$', 'article.views.hello_template_simple'),
url(r'', 'article.views.hello_template'),
Now any URL which isn't matched by hello_template_simple will be caught by hello_template.
I would like to show an 404 error if there's no proper entry in project_name/urls.py.
I read Writing your first Django app but i don't understood how to create a general error - not only for an app.
So i tried this:
TEMPLATE_DIRS = /var/www/first/templates
echo "404 ERROR" > /var/www/first/templates/404.html
in /var/www/first/urls.py:
from django.http import Http404
try:
...
url(r'^admin/', include(admin.site.urls)),
...
except:
raise Http404
After all i still get a 500 error if i call an unknown url.
Django uses the urls.py file to evaluate all the url patterns by order. If you want it to go to a certain page after it evaluated all the regex patterns and found no match, just add something like this as the last item in the urlpatterns tuple:
url('', views.defaultview),
with defaultview possibly being that 404 page.
django.views.defaults.page_not_found is a built-in django view that renders whatever's in templates/404.html.
It works with following in /var/www/first/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
...,
url(r'^admin/', include(admin.site.urls)),
...,
)
I have a project with three applications installed. The first (photologue) is working fine, but I'm having problems with the last two. My urls.py file in the Django site looks like this:
from django.conf.urls.defaults import patterns, include, url
from django.contrib import auth
from django.contrib import admin
from funvisis.users.models import FVISUser
admin.site.register(FVISUser)
admin.autodiscover()
urlpatterns = patterns(
'',
(r'^admin/', include(admin.site.urls)),
(r'^photologue/', include('photologue.urls')),
(r'^inspeccionespuentes/', include('funvisis.bridgeinspections.urls')),
(r'^inspeccionesedificios/', include('funvisis.buildinginspections.urls')),
)
The urls.py file on both of my applications looks like:
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
from .admin import admin_site
from .views import csv_view
urlpatterns = patterns('',
url(r'^csv/(?P<models_url>\w+)/', csv_view),
(r'', include(admin_site.urls),
)
The problem arise when I try to reach the url "^inspeccionesedificios/", since there is no link to add a new buildinginspection and the link to list all the inspections is formed as "http://127.0.0.1:8000/inspeccionespuentes/buildinginspections/" (note how it starts with "inspeccionespuentes" rather than "inspeccionesedificios").
If I change the order of the patterns in the Django site from:
(r'^inspeccionespuentes/', include('funvisis.bridgeinspections.urls')),
(r'^inspeccionesedificios/', include('funvisis.buildinginspections.urls')),
to:
(r'^inspeccionesedificios/', include('funvisis.buildinginspections.urls')),
(r'^inspeccionespuentes/', include('funvisis.bridgeinspections.urls')),
results in the same behaviour but with the problem in "inspeccionespuentes".
I have recently migrated from Django 1.3 to Django 1.4 and this problem ain't appeared before the migration. Any idea?
Thanks!