requested url not found with production setting in django - python

My website runs with no problem when DEBUG is set to true. but i get requested url not found error when i run the server in production setting. the admin page is fine.
this is my project urls.py:
urlpatterns = patterns('',
url(r'^', include('photography.urls')),
url(r'^admin/', include(admin.site.urls)),
# url(r'^$', 'photography.views.hello_world', name='home'),
)
this is my app urls.py:
urlpatterns = patterns('photography.views',
url(r'^$', views.index, name='index'),
url(r'^albums/(?P<slug>[a-zA-Z0-9-]+)/$', views.photos_by_location, name='photos_by_location'),
)
For testing purpose, i added a hello world view and it gets rendered with commented line in project urls.py. so I guess my way of including app urls is not really good when DEBUG is false . Is there a way to include my app urls that works in production setting?
Any help would be appreciated. thanks.
Update:
tried url(r'^/', include('photography.urls')), with a / after ^. didnt work either.

Related

django wagtail page not found when i don't use "127.0.0.1:8000"

I have added the following to my settings.py
ALLOWED_HOSTS = ['0.0.0.0','127.0.0.1','192.168.0.05']
My url.py
urlpatterns = [
url(r'^django-admin/', include(admin.site.urls)),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
#url(r'^search/$', search_views.search, name='search'),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
#url(r'', include(wagtail_urls)),
# Alternatively, if you want Wagtail pages to be served from a subpath
# of your site, rather than the site root:
# url(r'^pages/', renders(wagtail_urls)),
url(r'^i18n/', include('django.conf.urls.i18n')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += i18n_patterns(
# These URLs will have /<language_code>/ appended to the beginning
url(r'^search/$', search_views.search, name='search'),
url(r'', include(wagtail_urls)),
#url(r'^$', include(wagtail_urls)),
)
The dilema is when I do "http://127.0.0.1:8000/en" it works just fine however when I do "http://192.168.0.5:8000/en/" from my mobile phone on the same lan or even from the laptop its hosted on I keep getting "Page not found (404)".
What would cause such behavior did I overlook something in my url.py.
I have tried running it as follows :
python manage.py runserver 192.168.0.13:8000
python manage.py runserver 0.0.0.0:8000
Non of which helps.
I know its not a firewall issue as the page not found is as a result of the django service responding.
Check the site records under Settings -> Sites in the Wagtail admin. When a request comes in, Wagtail will only serve a page if the hostname matches one named in a site record, or the 'is default site' box is checked.

python social auth 404 error

I have create test application with pythn-social-aut in which I login using facebook.
When i click in the facebook link it redirect me to facebook login page. It works correctly
After test app I integrate in application but when i click on the facebok login link it give me 404 error. Even I check step by step but found whats the reason.
I inspect the link its href=/login/facebook/ is correct but not redirect me to facebook login page
here my code
under my main urls.py i have paste
urlpatterns = patterns('',
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^admin/', include(admin.site.urls)),
(r'^tinymce/', include('tinymce.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
(r'^', include('app.urls')),
url(r'^(?i)login/$', login, {'template_name': 'login.html'}),
url(r'^(?i)logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Inside my app.urls
urlpatterns = patterns('',
url(r'^socialcheck/$', 'app.views.socialCheck'),
)
100% working in the test app but in main project when i integrate it give 404 error when i click on link
It is a very good chance that your problem is in the urls.py code which you doesn't show. I suspect that some of the urls catches the ^/login/([^/]+)/ pattern but doesn't handle the /login/facebook/ path.
Try to move the social urls to the top of your urls.py. Set it as the first item of the patterns():
urlpatterns = patterns('',
url('', include('social.apps.django_app.urls', namespace='social')),
...
)

how to set the index page in django like http://127.0.0.1:8000/

I have created a small project like this structure..
|-mysite
|-polls
|---static
|-----polls
|-------css
|---------images
|-------images
|-------js
|---templates
|-----polls
|-templates
|---admin
Here In polls is the app and now i am getting output with this url http://127.0.0.1:8000/polls/
In main folder i.e mysite folder in urls.py i have code like this..
urlpatterns = patterns('',
url(r'^polls/',include('polls.urls',namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
Now in polls folder in urls.py code is..
urlpatterns = patterns('',
url(r'^$',views.index, name = 'index'),
}
Now i want to get the page like main website address like.. http://127.0.0.1:8000/
How to get?
Thanks.
Can you change what you have here
url(r'^polls/',include('polls.urls',namespace="polls")),
to
url(r'^', include('polls.urls', namespace="polls")),
Now the reason is this:
Django urls uses regex. In your example, you're telling django to catch your polls app, beginning from the url as localhost:8000/polls/
Learn more: https://docs.djangoproject.com/en/dev/topics/http/urls/
Even in your root project urls.py, you've got this:
# Examples:
# url(r'^$', 'Toolkit.views.home', name='home'), #this will match url of the type localhost:8000
# url(r'^blog/', include('blog.urls')), # this will match url of the type localhost:8000/blog/
Just look sharp!

Django new views not being added?

I started going through tut but then got stuck on the page.
tutorial page 3 - django
I exactly followed the tut to the point where it asks to goto localhost:8000/polls/.
There starts the problem, it is not working, states an error
Please, tell how to correct the error.
That page is a 404 page not found. This suggests to me that you have either not configured your URL's correctly or it's missing.
/project/urls.py
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
)
Where polls.urls points to your app URL at /polls/urls.py
So now in your polls/url.py add the index as described.
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
)
https://docs.djangoproject.com/en/1.6/intro/tutorial03/#write-your-first-view

django urlpatterns order

I ran into a problem loading the admin section of my django site with the following error:
No FlatPage matches the given query.
I managed to solve the problem, but I'm attempting to understand why it solved the problem. In my urls.py file, I moved the url(r'', include('django.contrib.flatpages.urls')), after the url(r'^admin/', include(admin.site.urls)), and voila, it worked. Can someone explain, briefly, why this would make a relevant difference? Should the admin url always be at the top of the list?
Code the produced the error:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
url (r'^blog/', include('blog.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'', include('django.contrib.flatpages.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
This is django 1.4.
The problem is that you have not installed the flatpages application correctly. Django's flatpages application relies on a piece of middleware that intercepts 404 requests. As a result, you do not need to add django.contrib.flatpages.urls to your urls.py.
You received that error because the regex you are using ('') matches all URLs. As a result, the urlpattern never reached ^admin/'.

Categories

Resources