0

我有以下创建和更新视图(django 1.5,Python 2.7):

class NewsCreateView(
        PermissionRequiredMixin,
        CreateView
    ):
    model = News
    template_name_suffix = "_create_form"
    form_class = NewsForm
    login_url = "/login/"
    permission_required = "news.add_news"

    def get_context_data(self, **kwargs):
        # Call the base implementation to get a context
        context = super(NewsCreateView, self).get_context_data(**kwargs)
        context['tags'] = News.tags.all()
        return context

    def form_valid(self, form):
        obj = form.save(commit = False)
        obj.slug = slugify(obj.headline)
        obj.writer = self.request.user.person
        obj.pub_date = datetime.datetime.now()
        obj.featured = False
        obj.enable_comments = True
        return super(NewsCreateView, self).form_valid(form)


class NewsUpdateView(
        PermissionRequiredMixin,
        UpdateView
    ):
    model = News
    template_name_suffix = "_update_form"
    form_class = NewsForm
    login_url = "/login/"
    permission_required = "news.change_news"

    def get_context_data(self, **kwargs):
        # Call the base implementation to get a context
        context = super(NewsUpdateView, self).get_context_data(**kwargs)
        context['tags'] = News.tags.all()
        return context

CreateView行为与预期的一样,UpdateView 仅在开发中。然而,在生产环境中,UpdateView自上次 Gunicorn 重启以来创建的任何新闻文章都会返回 404。重新启动 Gunicorn 可使所有UpdateView页面正常工作。

我无法获得太多有用的调试信息,因为我无法在我的开发环境中重新创建错误。有谁知道这里发生了什么?

更新根据要求,这里是在这个模型上工作的经理。从models.py

# visibility
all_news =  models.Manager()
objects = LiveNewsManager()

并从managers.py

class LiveNewsManager(models.Manager):
    def get_query_set(self):
        return super(LiveNewsManager, self).get_query_set().filter(status = self.model.LIVE_STATUS).filter(pub_date__lt = timezone.now())
4

0 回答 0