Moving to production environment broke my application - django

I've just deployed my application on dreamhost and it's stopped working when uploading files. Passenger just produces a 500 internal error. It works on my development set up.
My passenger file looks like:
import sys, os
sys.path.append(os.getcwd())
sys.path.append(os.path.join(os.getcwd(), '/photosoc'))
os.environ['DJANGO_SETTINGS_MODULE'] = "photosoc.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I get the standard 404 error(debug is still enabled). I have had to change my urls file though from:
from django.conf.urls.defaults import patterns, include, url
from competition.models import Image
from competition import *
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
admin.site.register(Image)
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'photosoc.views.home', name='home'),
# url(r'^photosoc/', include('photosoc.foo.urls')),
# 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'^image/$', 'competition.views.index'),
url(r'^image/uploadImage', 'competition.views.uploadImage'),
url(r'^image/uploadCompleted', 'competition.views.uploadCompleted'),
url(r'^image/uploadFailed', 'competition.views.uploadFailed'),
)
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}))
To the following:
from django.conf.urls.defaults import patterns, include, url
from competition.models import Image
from competition import *
from django.contrib import admin
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
admin.site.register(Image)
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'photosoc.views.home', name='home'),
# url(r'^photosoc/', include('photosoc.foo.urls')),
# 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'^image/$', 'competition.views.index'),
url(r'^image/uploadImage', 'competition.views.uploadImage'),
url(r'^image/uploadCompleted', 'competition.views.uploadCompleted'),
url(r'^image/uploadFailed', 'competition.views.uploadFailed'),
)
This is the only change I've made to the application from the switch from development to production. So what else could have gone wrong?

You may have a permission problem.
It seems like you are writing image files. Does the process that is running Django have permission to write files? When you are running Django locally with ./manage.py runserver Django will get the permissions of the user that runs from the command line, but in a typical production environment you'd be running with the permissions of the Apache user. This user may not have permission to write those image files. You could try temporarily hardcoding the write directory to /tmp to see if that makes a difference.
Of course, you will really need see that 500 error stack trace to know what's going on.

Are your settings exactly the same in what middleware classes your importing? Double check that these are the same.
Related:
ModSecurity: Output filter: Failed to read bucket (rc 104): Connection reset by peer

Related

Rewrite URL to exclude Django application name

on my live server, I am trying to remove/rewrite the need to include the application name in the URL, as without it I get a 404. For example:
http://www.example.com/myapp/page.html
to
http://www.example.com/page.html
This is especially tricky since i don't want this to affect the django admin URL which excludes the app name.
This is on Apache Server on Ubuntu on a shared host (A2).
You're root urls.py most likely looks something like this:
"""
Definition of urls for api.
"""
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
urlpatterns = [
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls),
url(r'^myapp/', include('myapp.urls'))
]
When you just replace r'^myapp/' with r'^' the app will be automatically tried, when there is nothing else before that fits (so it's best to put it to the end of the list)

Django - Page not found (404) for URL

I am getting the following error when ever I access the url's except /home.
Page not found (404)
Request Method: GET Request URL
Using the URLconf defined
in report_ui.urls, Django tried these URL patterns, in this order:
^admin/
^home/
The current URL, individual/, didn't match any of
these. You're seeing this error because you have DEBUG = True in your
Django settings file. Change that to False, and Django will display a
standard 404 page.
The code :
urls.py
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
urlpatterns = patterns('dnslog.views',
# Examples:
url(r'$', 'home'),
url(r'^report/$', 'report'),
url(r'^angular/$', 'angular'),
url(r'^linear/$', 'LinearPrediction'),
url(r'^splunk/$', 'splunkdata'),
url(r'^toyprediction/$', 'toyprediction'),
url(r'^saleprediction/$', 'GetSalesPrediction'),
url(r'^customerprediction/$', 'GetCustomerPrediction'),
url(r'^monthwiseprediction/$', 'GetMonthWiseSalesPrediction'),
url(r'^getlinearprediction/(?P<duration>.\w+)/$', 'GetLinearPrediction'),
url(r'^getprediction/$', 'GetPredictionReport'),
url(r'^modeldata/(?P<obj>.\w+)/$', 'GetConsolidatedObjectData'),
# url(r'^modeldata/(?P<date>\d{4}-\d{2}-\d{2})/$', 'GetConsolidatedObjectData'),
url(r'^home/(?P<date>\d{4}-\d{2}-\d{2})/$', 'GetConsolidateHits'),
url(r'^bytes/$', 'BytesDownload'),
url(r'^BytesDownload/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetConsolidateDownloadBytes'),
url(r'^getCntPerData/$', 'GetConsolidateCntPer'),
url(r'^help/$', 'help'),
url(r'^individualhits/$', 'individualhits'),
url(r'^individualhits1/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualHits'),
url(r'^bubble/$', 'bubble'),
url(r'^bubblechart/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetConsolidateHitsForBubble'),
#url(r'^test/$', 'test'),
url(r'^domaincloud/$', 'cloud'),
url(r'^getdomaincloud/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getclouddata'),
url(r'^circleview/$', 'circle'),
url(r'^getcircleview/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcircledata'),
url(r'^comparisionview/$', 'comparision'),
url(r'^getcomparision/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcomparisiondata'),
url(r'^individualcomparision/(?P<domain>.+)/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualComparisonData'),
url(r'^trendview/$', 'trend'),
url(r'^gettrendview/$', 'Gettrenddata'),
url(r'^zoomabletree/$', 'zoomabletree'),
url(r'^getzoomabletree/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcircledata'),
##url(r'^report_ui/', include('report_ui.foo.urls')),
#url(r'^individualConsolidatedHits/$', 'individualConsolidatedHits'),
url(r'^getConsolidatedCategoryDetails/(?P<date>\d{4}-\d{2}-\d{2})/$',
'getConsolidatedCategoryDetails'),
# overall individual reports
url(r'^individual/$', 'individual'),
## individual Category report
#url(r'^individualcategory/$', 'individualcategory'),
url(r'^GetIndividualCategory/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualCategory'),
url(r'^twitter/$','twitter'),
root urls.py
from django.conf.urls import patterns, include, url
# to include the media url
from django.conf import settings
from django.conf.urls.static import static
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'report_ui.views.home', name='home'),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^home/', include('dnslog.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
)
Any help would be appreciated. Thanks!
Either change your root urls.py
url(r'^home/', include('dnslog.urls')),
to:
url(r'^/', include('dnslog.urls')),
Or change your request from
from:
individual/
to:
/home/individual

Why an extra slash is getting added to urls?

I've created a blog using django and hosted it on dotcloud http://www.honeybunny.dotcloud.com/blog/ its working fine on the localhost but when i try to access it online an extra slash is added to the urls what could be the reason ?
www.sitename.com/admin/
becomes
www.sitename.com//admin/
my urls.py is as following
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
import blog
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$',redirect_to,{'url':'/blog'}),
url(r'^admin/', include(admin.site.urls)),
url(r'^blog/',include('blog.urls')),
)
Also submitting the login form on the admin redirects me to http://admin/ while in the local environment it works perfectly fine .
UPDATE : My problem seems remarkably similar to the one described here .
From django tutorials the url file should look like the one below.
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^articles/2003/$', 'news.views.special_case_2003'),
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'honeybunny.views.home', name='home'),
# url(r'^honeybunny/', include('honeybunny.foo.urls')),
# 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'^$',redirect_to,{'url':'/blog'}),
url(r'^admin/$', include(admin.site.urls)),
)
Is my urls.py file
I have deleted import blog line because I don't have blog module.
It seemed to be a problem with dotcloud the same code worked without any errors when i uploaded it to epio

NameError:Admin not found in django

The urls.py of the project is this
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Sdr.views.home', name='home'),
# url(r'^Sdr/', include('Sdr.foo.urls')),
# 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)),
(r'', include('Sdr.sdr.urls')),
)
The urls.py of the app looks like this
# Import django modules
from django.conf.urls.defaults import *
from django.contrib import admin
# Import custom modules
import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
(r'', include('Sdr.sdr.urls')),
)
The error I am getting is exception found is
Django Version: 1.3
Exception Type: NameError
Exception Value:
name 'admin' is not defined
You forgot to import admin in the project's urls.py. Read harder.
Uncomment the following in your project's urls.py.
from django.contrib import admin
admin.autodiscover()
Faced with the same problem in tutorial.
Try to add in models.py:
from django.contrib import admin

Django Admin application no working on URL

In my urls file I have configured the Django admin application to run off the url /adminDJ/. However it doesn't run. It loads up my own admin stuff. Here is my urls.py:
(r'^admin/add/member/$', 'astonomyStuff.attendance.views.newMember'),
(r'^admin/add/$', 'astonomyStuff.attendance.views.addPage'),
(r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^adminDJ/$', include(admin.site.urls)),
(r'^talks/$', 'astonomyStuff.attendance.views.talksIndex'),
(r'^talks/past/$', 'astonomyStuff.attendance.views.viewAllTalks'),
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'),
(r'^members/(?P<member_number>[^/]+)/$', 'astonomyStuff.attendance.views.viewMember'),
(r'^members/(?P<member_number>[^/]+)/delete$', 'astonomyStuff.attendance.views.deleteMember'),
(r'^admin/add/talk/$', 'astonomyStuff.attendance.views.newTalk'),
(r'^talks/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewTalk'),
(r'^attendance/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewAttendance'),
(r'^databrowse/(.*)', databrowse.site.root),
(r'^adminDoc/doc/', include('django.contrib.admindocs.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^accounts/profile/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^admin/add/attendance/$', 'astonomyStuff.attendance.views.addAttendance'),
(r'^members/(?P<member_number>[^/]+)/edit$', 'astonomyStuff.attendance.views.editMember'),
(r'^public/talks/$', 'astonomyStuff.attendance.views.publicViewTalks')
I have rearranged the order to see if this was the problem but that's not fixed it. Must the django admin application run on /admin/?
Edit
I have had the admin application working before just to let you know it only broke when I played around with the urls.
Edit 2
Here is my complete urls.py:
from django.conf.urls.defaults import *
from astonomyStuff.attendance.models import Member
from astonomyStuff.attendance.models import Non_Member
from astonomyStuff.attendance.models import Talk
from astonomyStuff.attendance.models import Event_Attendance
from django.contrib import admin
from django.contrib import databrowse
admin.autodiscover()
admin.site.register(Member)
admin.site.register(Non_Member)
admin.site.register(Talk)
admin.site.register(Event_Attendance)
databrowse.site.register(Member)
databrowse.site.register(Non_Member)
databrowse.site.register(Talk)
databrowse.site.register(Event_Attendance)
urlpatterns = patterns('',
# Example:
# (r'^astonomyStuff/', include('astonomyStuff.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/add/member/$', 'astonomyStuff.attendance.views.newMember'),
# (r'^admin/add/$', 'astonomyStuff.attendance.views.addPage'),
# (r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^admin/$', include(admin.site.urls)),
(r'^talks/$', 'astonomyStuff.attendance.views.talksIndex'),
(r'^talks/past/$', 'astonomyStuff.attendance.views.viewAllTalks'),
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'),
(r'^members/(?P<member_number>[^/]+)/$', 'astonomyStuff.attendance.views.viewMember'),
(r'^members/(?P<member_number>[^/]+)/delete$', 'astonomyStuff.attendance.views.deleteMember'),
# (r'^admin/add/talk/$', 'astonomyStuff.attendance.views.newTalk'),
(r'^talks/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewTalk'),
(r'^attendance/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewAttendance'),
(r'^databrowse/(.*)', databrowse.site.root),
(r'^adminDoc/doc/', include('django.contrib.admindocs.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^accounts/profile/$', 'astonomyStuff.attendance.views.adminPage'),
# (r'^admin/add/attendance/$', 'astonomyStuff.attendance.views.addAttendance'),
(r'^members/(?P<member_number>[^/]+)/edit$', 'astonomyStuff.attendance.views.editMember'),
(r'^public/talks/$', 'astonomyStuff.attendance.views.publicViewTalks'),
)
Not this (r'^adminDJ/$', include(admin.site.urls)),
But this (r'^adminDJ/', include(admin.site.urls)), ##note, no $ in the regex
Remember folks, gotta check your regexes...
This is probably nothing but it caught my eye. From the first snippet:
(r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^adminDJ/$', include(admin.site.urls)),
And the second snippet:
(r'^admin/$', include(admin.site.urls)),
Is this how you want it? The first snippet uses ^adminDJ/$ while the second one uses admin/$ opposite include(admin.site.urls).
Are these two files? And are the both used? In that case the first snippet could very well override the second, thereby causing your admin views to show up instead of Django's.