Save in Django Admin有时会失败

时间:2021-01-12 00:21:19

I have a portfolio page with django, and i'm noticing a strange behaviour when a try to save an edited entry. It saves, and then it seems that the redirect fails to catch the ID and then goes to a 404 page that says domain.com/admi/internal_error.html/ in the URL (note the admi, sometimes is ad or adm). It happens with both 'Save' and 'Save and continue editing'.

我有一个带django的投资组合页面,当试图保存编辑的条目时,我注意到了一个奇怪的行为。它保存,然后重定向似乎无法捕获ID,然后转到URL中的404页面(注意admi,有时是ad或adm)。“保存”和“保存并继续编辑”都会发生这种情况。

This is my model

这是我的模型

from django.db import models
from ramonlapenta.portfolio.managers import EntryManager
from ramonlapenta.slughifi import slughifi

class Type(models.Model):
    type = models.CharField(max_length=100)

    def __unicode__(self):
        return self.type

class Entry(models.Model):
    type = models.ForeignKey(Type)
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100)
    slug = models.SlugField()
    description = models.TextField()
    requirement = models.TextField()
    solution = models.TextField()
    url = models.CharField(blank=True, max_length=64)
    published = models.BooleanField(db_index=True, default=True)
    logo = models.ImageField(upload_to="logos")
    image = models.ImageField(upload_to="portfolio", height_field='height', width_field='width')
    height = models.CharField(max_length=3)
    width = models.CharField(max_length=3)

    objects = EntryManager()

    def __unicode__(self):
        return u"%s - %s" % (self.title, self.created) 

    class Meta:
        verbose_name_plural = "entries"

    def save(self, *args, **kwargs):
        self.slug = slughifi(self.title)
        super(Entry, self).save(*args, **kwargs)

And this is the admin.py

这是admin。py

from django.contrib import admin
from ramonlapenta.portfolio.models import Type
from ramonlapenta.portfolio.models import Entry
from django import forms

class EntryAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Title', {'fields' : ['title']}),
        ('Address', {'fields' : ['url']}),
        ('Description', {'fields' : ['description','requirement','solution']}),
        ('Type', {'fields' : ['type']}),
        ('Image', {'fields' : ['logo', 'image']}),
    ]
    list_display = ('title', 'created')
    list_filter = ['created', 'type']

admin.site.register(Type)
admin.site.register(Entry, EntryAdmin)

This is my entry manager, where i only filter the results.

这是我的入口管理器,我只过滤结果。

from django.db import models

class EntryManager(models.Manager):
    def published(self):
        return self.model.objects.filter(published=True).order_by('-id')

This is the general urls.py

这是通用url

from django.conf.urls.defaults import patterns, include, url
from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^', include('site.pages.urls')),
    (r'^', include('site.blog.urls')),
    (r'^', include('site.portfolio.urls')),
    (r'^admin/', include(admin.site.urls)),
)

And the portfolio urls.py

和组合urls . py

from django.conf.urls.defaults import *

从django.conf.urls.defaults进口*

urlpatterns = patterns('ramonlapenta.portfolio.views',
    url(r'^portfolio/$', 'index', name="port-main"),
    url(r'^portfolio/(?P<item_slug>[a-zA-Z0-9_.-]+)/$', 'detail', name="port-slug"),
    url(r'^portfolio/type/(?P<type>[a-zA-Z0-9_.-]+)/$', 'type', name="port-type")
)

Thos is what i see with HttpFox: Save in Django Admin有时会失败

这就是我看到的HttpFox:

Note: everything else works fine, even there it sometimes works fine, and the public site works fine too. The problem is just editing a portfolio entry.

注意:其他一切都很好,即使在那里有时也很好用,而且公共场所也很好用。问题只是编辑一个投资组合条目。

Does anybody knows why is this happening and how can i fix it?

有人知道为什么会发生这种情况吗?

5 个解决方案

#1


1  

My guess is that the main url.py is catching some of the admin data (being that any admin action will be considered by all the other urlconfs.

我猜是主url。py正在捕获一些管理数据(因为所有其他urlconfs都将考虑任何管理操作。

Try to put the admin urls at the top:

尝试将管理url放在顶部:

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^', include('site.pages.urls')),
    (r'^', include('site.blog.urls')),
    (r'^', include('site.portfolio.urls')),
)

Edit: second guess

编辑:第二次猜

The key information is that second 302 in the request list. Someone (probably dreamost's apache) is eating the response and returning a redirect to a custom page.

关键信息是请求列表中的第二个302。有人(可能是dreamost的apache)正在接收响应并返回到自定义页面的重定向。

In this case setting DEBUG = True is of no help, because the response would have anyway the same error.

在这种情况下,将DEBUG = True设置为没有帮助,因为响应无论如何都会有相同的错误。

This means two things:

这意味着两件事:

  1. You have an error somewhere in your Model's code, probably some attribute/field/property that's used to display the object.

    在模型的代码中有一个错误,可能是用于显示对象的某个属性/字段/属性。

    To isolate the error, try to find a pattern on which specific values trigger the error and which values allows to load the admin form.

    要隔离错误,请尝试找到一个模式,其中特定的值触发错误,哪些值允许加载管理表单。

  2. You can't see the django error page unless you either work locally in the development server (manage.py runserver) or disable custom error pages in dreamhost as other suggest.

    除非您在开发服务器中本地工作(管理),否则您无法看到django错误页面。如其他建议,在dreamhost中禁用自定义错误页。

#2


1  

Knowing your setup and what appears in server logs at the time you're saving an entry might help us locate a problem. It's likely that the cause is outside Django (since the bug is not reproducible under Django's development server).

了解您的设置和在保存条目时在服务器日志中出现的内容可能会帮助我们找到问题。原因很可能是Django之外的原因(因为在Django的开发服务器下,bug是不可复制的)。

Anyway, you might find some of these solutions relevant:

不管怎样,你可能会发现一些相关的解决方案:

  • Django on dreamhost problem (old post, but symptoms described there are similar, might be relevant if you're running Django on FastCGI).
  • Django在dreamhost问题上(旧的post,但是有类似的症状,如果你在FastCGI上运行Django,可能是相关的)。
  • getting 500 internal server error with django on dreamhost (in short: just try re-create the whole setup and see if that helps).
  • 在dreamhost上使用django获得500个内部服务器错误(简而言之:尝试重新创建整个设置,看看是否有帮助)。
  • Or you may want simply to google dreamhost django 500 in case you haven't already, seems like people frequently encounter similar problem while setting up Django on Dreamhost.
  • 或者,您可能只想要谷歌dreamhost django 500,以防您还没有遇到类似的问题,似乎人们在dreamhost上设置django时经常遇到类似的问题。

#3


0  

I'll be curious to see your urls.py . My guess is that the regex for the admin site is bogus.

我很好奇你的网址。py。我猜管理员网站的regex是假的。

#4


0  

For sure an error is happening when you save those entries and you should check your logs. Or try reproduce it with DEBUG=True

当您保存这些条目时,肯定会发生错误,您应该检查您的日志。或者尝试用DEBUG=True复制它

My guess is that you are using dreamhost and Dreamhost allows you to define custom error pages and "internal_error.html" is for the status 500 error page (see : http://wiki.dreamhost.com/Creating_custom_error_pages).

我猜您正在使用dreamhost和dreamhost,它们允许您定义自定义错误页面和“internal_error”。html“用于状态500错误页面(参见:http://wiki.dreamhost.com/Creating_custom_error_pages)。

#5


0  

Try to have a look at your dreamhost error.log file.

试着看看你的dreamhost错误。日志文件。

The sure thing is that the problem comes from your dreamhost configuration and not your django code (since it is working properly in development with Django 1.2)

可以肯定的是,问题来自于您的dreamhost配置,而不是django代码(因为它在django 1.2的开发中正常工作)

#1


1  

My guess is that the main url.py is catching some of the admin data (being that any admin action will be considered by all the other urlconfs.

我猜是主url。py正在捕获一些管理数据(因为所有其他urlconfs都将考虑任何管理操作。

Try to put the admin urls at the top:

尝试将管理url放在顶部:

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^', include('site.pages.urls')),
    (r'^', include('site.blog.urls')),
    (r'^', include('site.portfolio.urls')),
)

Edit: second guess

编辑:第二次猜

The key information is that second 302 in the request list. Someone (probably dreamost's apache) is eating the response and returning a redirect to a custom page.

关键信息是请求列表中的第二个302。有人(可能是dreamost的apache)正在接收响应并返回到自定义页面的重定向。

In this case setting DEBUG = True is of no help, because the response would have anyway the same error.

在这种情况下,将DEBUG = True设置为没有帮助,因为响应无论如何都会有相同的错误。

This means two things:

这意味着两件事:

  1. You have an error somewhere in your Model's code, probably some attribute/field/property that's used to display the object.

    在模型的代码中有一个错误,可能是用于显示对象的某个属性/字段/属性。

    To isolate the error, try to find a pattern on which specific values trigger the error and which values allows to load the admin form.

    要隔离错误,请尝试找到一个模式,其中特定的值触发错误,哪些值允许加载管理表单。

  2. You can't see the django error page unless you either work locally in the development server (manage.py runserver) or disable custom error pages in dreamhost as other suggest.

    除非您在开发服务器中本地工作(管理),否则您无法看到django错误页面。如其他建议,在dreamhost中禁用自定义错误页。

#2


1  

Knowing your setup and what appears in server logs at the time you're saving an entry might help us locate a problem. It's likely that the cause is outside Django (since the bug is not reproducible under Django's development server).

了解您的设置和在保存条目时在服务器日志中出现的内容可能会帮助我们找到问题。原因很可能是Django之外的原因(因为在Django的开发服务器下,bug是不可复制的)。

Anyway, you might find some of these solutions relevant:

不管怎样,你可能会发现一些相关的解决方案:

  • Django on dreamhost problem (old post, but symptoms described there are similar, might be relevant if you're running Django on FastCGI).
  • Django在dreamhost问题上(旧的post,但是有类似的症状,如果你在FastCGI上运行Django,可能是相关的)。
  • getting 500 internal server error with django on dreamhost (in short: just try re-create the whole setup and see if that helps).
  • 在dreamhost上使用django获得500个内部服务器错误(简而言之:尝试重新创建整个设置,看看是否有帮助)。
  • Or you may want simply to google dreamhost django 500 in case you haven't already, seems like people frequently encounter similar problem while setting up Django on Dreamhost.
  • 或者,您可能只想要谷歌dreamhost django 500,以防您还没有遇到类似的问题,似乎人们在dreamhost上设置django时经常遇到类似的问题。

#3


0  

I'll be curious to see your urls.py . My guess is that the regex for the admin site is bogus.

我很好奇你的网址。py。我猜管理员网站的regex是假的。

#4


0  

For sure an error is happening when you save those entries and you should check your logs. Or try reproduce it with DEBUG=True

当您保存这些条目时,肯定会发生错误,您应该检查您的日志。或者尝试用DEBUG=True复制它

My guess is that you are using dreamhost and Dreamhost allows you to define custom error pages and "internal_error.html" is for the status 500 error page (see : http://wiki.dreamhost.com/Creating_custom_error_pages).

我猜您正在使用dreamhost和dreamhost,它们允许您定义自定义错误页面和“internal_error”。html“用于状态500错误页面(参见:http://wiki.dreamhost.com/Creating_custom_error_pages)。

#5


0  

Try to have a look at your dreamhost error.log file.

试着看看你的dreamhost错误。日志文件。

The sure thing is that the problem comes from your dreamhost configuration and not your django code (since it is working properly in development with Django 1.2)

可以肯定的是,问题来自于您的dreamhost配置,而不是django代码(因为它在django 1.2的开发中正常工作)