Django的:不允许的方法(POST):

问题描述 投票:0回答:1

我想传递一个时间戳到一个Django CreateView的的网址在FullCalendar的事件。不过,按下后提交我的形式我不断收到空白页和错误的:

Method Not Allowed (POST): /fullcalendar/ambroses-calendar/

HTML:

dayClick: function(date, jsEvent, view) {
    if($('#calendar').fullCalendar('getView').type != 'month') {
        $("#occDiv").load("{% url 'edit_occurrence_short' 1234567898765 %}".replace(1234567898765, (new Date(date)).getTime())).dialog({
        autoOpen: false,
        modal: true,
        bgiframe: true,
        width: 800
    });
    $("#occDiv").dialog('open');
}

URLs.朋友

   url(r'^occurrence/add/(?P<date>\d+)/$',
        ShortCreateOccurrenceView.as_view(),
        name='edit_occurrence_short')

views.朋友:

class ShortOccurrenceMixin(CalendarViewPermissionMixin, TemplateResponseMixin):
    model = Occurrence
    pk_url_kwarg = 'occurrence_id'
    form_class = ShortOccurrenceForm

class ShortCreateOccurrenceView(ShortOccurrenceMixin, CreateView):
    template_name = 'schedule/edit_occurrence_short.html'

    def form_valid(self, form):
        occurrence = form.save(commit=False)
        start = datetime.datetime.fromtimestamp(self.kwargs.get('date', None)/1000.0)
        end = start + datetime.timedelta(hours=1)
        occurrence.start = start
        occurrence.end = end
        occurrence.save()
        return HttpResponseRedirect('home')

models.朋友:

class Occurrence(models.Model):
    event = models.ForeignKey(Event, on_delete=models.CASCADE, verbose_name=_("event"))
    title = models.CharField(_("title"), max_length=255, blank=True)
    description = models.TextField(_("description"), blank=True)
    start = models.DateTimeField(_("start"), db_index=True)
    end = models.DateTimeField(_("end"), db_index=True)
    cancelled = models.BooleanField(_("cancelled"), default=False)
    original_start = models.DateTimeField(_("original start"), auto_now=True)
    original_end = models.DateTimeField(_("original end"), auto_now=True)
    created_on = models.DateTimeField(_("created on"),   auto_now_add=True)
    updated_on = models.DateTimeField(_("updated on"), auto_now=True)

forms.朋友:

class ShortOccurrenceForm(forms.ModelForm):
    class Meta(object):
        model = Occurrence
        fields = ('title', 'event')

python django
1个回答
0
投票

问题下的评论使我正确的答案。非常感谢您@Willhen范Onsem和@dirkgroten!

我能够通过设置窗体上的动作在html改变表单POST的起源

...
<form action="{% url 'edit_occurrence_short' date %}" method="post" >
...
© www.soinside.com 2019 - 2024. All rights reserved.