在django中生成urls.pyc文件的问题,如何解决?

时间:2014-10-28 12:55:58

标签: python django nginx gunicorn

我们已经在django 1.6.4中将应用程序升级到Django 1.7,我使用nginx和gunicorn来提供应用程序。

随机应用程序返回以下错误:

TypeError at /admin/ihs_booking/occupancydiscount/add/
 'tuple' object is not callable
 Request Method:    POST
 Request URL:   http://localhost/admin/ihs_booking/occupancydiscount/add/
 Django Version:    1.7
 Exception Type:    TypeError
 Exception Value: 'tuple' object is not callable
 Exception Location:    /usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py in message_user, line 1016
 Python Executable: /usr/bin/python
 Python Version:    2.7.6

我们尝试更改apache尝试但仍然是同样的问题。

经过调查我们得出结论,问题发生在urls.pyc生成。

我们删除pyc,重新启动服务器(apache或nginx + gunicorn)并且它可以工作。

一段时间后,问题再次出现。

这是urls.py的内容:

#-*- coding=utf-8 -*-
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib import admin

from .views import home, search, book, confirm_payment, gestion, contact_ihs, test_calendar

admin.autodiscover()

urlpatterns = patterns('',
 # Examples:
 # url(r'^blog/', include('blog.urls')),
 url(r'^$', home, name='home'),
 url(r'^calendar/$', test_calendar, name='test_calendar'),
 url(r'^search/$', search, name='search'),
 url(r'^gestion/$', gestion, name='gestion'),
 url(r'^book/$', book, name='search'),
 url(r'^confirm-payment/$', confirm_payment, name='confirm'),
 url(r'^contact/', contact_ihs, name='contact'),
 url(r'^admin/', include(admin.site.urls),)
)

 #Defining the URLs to upload media files
if settings.DEBUG:
 urlpatterns += patterns(
     'django.views.static',
     (r'media/(?P<path>.*)',
     'serve',
     {'document_root': settings.MEDIA_ROOT}), )

我们必须使用nginx + gunicorn运行应用程序,因为需要在同一台服务器上运行django和php。

有什么想法吗? 谢谢!

这里是1061行周围的admin / options.py。

def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
    opts = self.model._meta
    app_label = opts.app_label
    preserved_filters = self.get_preserved_filters(request)
    form_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, form_url)
    view_on_site_url = self.get_view_on_site_url(obj)
    context.update({
        'add': add,
        'change': change,
        'has_add_permission': self.has_add_permission(request),
        'has_change_permission': self.has_change_permission(request, obj),
        'has_delete_permission': self.has_delete_permission(request, obj),
        'has_file_field': True,  # FIXME - this should check if form or formsets have a FileField,
        'has_absolute_url': view_on_site_url is not None,
        'absolute_url': view_on_site_url,
        'form_url': form_url,
        'opts': opts,
        'content_type_id': get_content_type_for_model(self.model).pk,
        'save_as': self.save_as,
        'save_on_top': self.save_on_top,
        'to_field_var': TO_FIELD_VAR,
        'is_popup_var': IS_POPUP_VAR,
        'app_label': app_label,
    })

我们在admin.py的list_display末尾有一个“,”我们删除了它,但错误仍然存​​在。

这是admin.py的一个类:

  class PromcodeDiscountAdmin(admin.ModelAdmin):
    list_display = ('code', 'hotel', 'name', 'discount_percentage', 'start', 'end', 'is_active', 'promotional_group')
    form = PromocodeAdminForm
  admin.site.register(PromcodeDiscount, PromcodeDiscountAdmin)

1 个答案:

答案 0 :(得分:0)

我知道这是一个yearago问题,但为了将来参考,
从中删除最后一个逗号  geom_boxplot