As a result of attempting to update admin.py of one of my Django apps, I now get a Server Error (500) that has brought my site down. When I import admin from django.contrib, I get the following traceback:
Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 74, in autodiscover_modules import_module('%s.%s' % (app_config.name, module_to_search)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) ImportError: No module named admin
Using print_stack() gives me a little deeper insight:
File "/home/ubuntu/gather/src/foodshop/wsgi.py", line 21, in <module> application = get_wsgi_application() File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application django.setup() File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 115, in populate app_config.ready() File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/apps.py", line 22, in ready self.module.autodiscover() File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 24, in autodiscover autodiscover_modules('admin', register_to=site) File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 74, in autodiscover_modules import_module('%s.%s' % (app_config.name, module_to_search)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/home/ubuntu/gather/src/recipes/admin.py", line 6, in <module> class RecipesAdmin(admin.ModelAdmin): File "/home/ubuntu/gather/src/recipes/admin.py", line 9, in RecipesAdmin traceback.print_stack()
I use this module in several other apps within my project, so I don't understand why it's not working for this particular app. You can see my very simple Python code below, which is for an admin.
admin.py
from django.contrib import admin
from .models import Recipes
class RecipesAdmin(admin.ModelAdmin):
list_display = ["__unicode__", "title", "rating", "date_modified"]
prepopulated_fields = {"slug": ("SKU",)}
class Meta:
model = Recipes
admin.site.register(Recipes, RecipesAdmin)
urls.py
from django.conf import settings from django.conf.urls import include, url from django.conf.urls.static import static from django.contrib import admin from django.conf.urls import patterns, url, include from djangoratings.views import AddRatingFromModel urlpatterns = [ url(r'^$', 'customers.views.home', name='home'), url(r'^home/', 'customers.views.home', name='home'), url(r'^about/', 'recipes.views.about', name='about'), url(r'^menu/', 'recipes.views.menu', name='menu'), url(r'^donate/', 'recipes.views.menu', name='menu'), # url(r'^contact/', 'recipes.views.contact', name='contact'), url(r'^admin/', include(admin.site.urls)), url(r'^about/healthy/', 'recipes.views.healthy', name='healthy'), url(r'^about/premade/', 'recipes.views.premade', name='premade'), url(r'^about/exceptional/', 'recipes.views.exceptional', name='exceptional'), url(r'^accounts/', include('registration.backends.default.urls')), url(r'^cart/', 'cart.views.get_cart', name='get_cart'), url(r'^add/', 'recipes.views.menu', name='menu'), # url(r'^add/(?P<product_id>[-\w]+)/id=(?P<quantity>[-\w]+)/$', 'cart.views.add_to_cart', name='shopping-cart-add'), url(r'^update/(?P<product_id>[-\w]+)/$', 'cart.views.specific_qty', name='shopping-cart-specify'), url(r'^remove/(?P<product_id>[-\w]+)/$', 'cart.views.remove_from_cart', name='shopping-cart-remove'), url(r'^subtract/(?P<product_id>[-\w]+)/$', 'cart.views.subtract_from_cart', name='shopping-cart-subtract'), url(r'^clear_cart/', 'cart.views.clear_cart', name='shopping-cart-clear'), url(r'^contact/$','contact.views.email',name='email'), url(r'^feedback/$','contact.views.feedback',name='feedback'), url(r'^thanks/$', 'contact.views.thanks',name='thanks'), url(r'^profile/$', 'cart.views.profile', name='profile'), url(r'^profile/new/$', 'cart.views.new_profile', name='new_profile'), url(r'^profile/error/$', 'cart.views.qty_error', name='qty_error'), url(r'^profile/cancel/$', 'cart.views.cancel_sub', name='cancel_sub'), url(r'^profile/feedback/$', 'recipes.views.feedback', name='feedback'), url(r'^rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(), { 'app_label': 'recipes', 'model': 'recipes', 'field_name': 'rating', }), url(r'^charge/$', 'cart.views.charge', name='charge'), url(r'^subscription/charge/$', 'cart.views.pay', name='pay'), url(r'^frequently_asked/$', 'cart.views.frequently_asked', name='frequently_asked'), url(r'^tender/$', 'cart.views.weekly_orders', name='weekly_orders'), url(r'^tender_postmates/$', 'cart.views.tender_postmates', name='tender_postmates') ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I have ensured that I am importing django.contrib.admin in settings.py, and in my urls.py file, I have from django.contrib import admin and url(r'^admin/', include(admin.site.urls)). This just started when I tried changing the admin.py file above; even after reverting back to the original file, the server error occurs. Unfortunately, this has brought my entire site down.
I'm using an Ubuntu machine and an Apache2 server. Any insights would be much appreciated!
Update 1: Even after doing a git reset --hard to origin/master, the error is still occurring.
Update 2: I have removed every .pyc file and restarted my Apache2 server, but the problem persists.
No comments:
Post a Comment