django返回空白页面

时间:2018-03-16 10:02:25

标签: python html django

我不确定代码有什么问题,

forms.py

from django.form import datetime, widgets
import datetime
import calendar
from bootstrap_datepicker.widgets import Datepicker



class DateForm(forms.Form):
    date_1=forms.DateTimeField(widget=DatePicker(
        options={"format": "dd/mm/yyyy",
        "autoclose": True }
        (help_text ='please enter a date',initial= "year/month/day")))
    def cleandate(self):
        c_date=self.cleaned_data['date_1']
        if date < datetime.date.today():
            raise ValidationError(_('date entered has passed'))
        elif date > datetime.date.today():
            return date_1

    def itamdate(forms.Form):
        date_check=calendar.setfirstweekday(calendar.SUNDAY)
        if c_date:
            if date_1==date_check:
                pass
            elif date_1!=date_check:
                raise ValidationError('The Market will not hold today')
            for days in list(range(0,32)):
                for months in list(range(0,13)):
                    for years in list(range(2005,2108)):



views.py

    from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
import datetime
from .forms import DateForm


def imarket(request):
        #CREATES A FORM INSTANCE AND POPULATES USING DATE ENTERED BY THE USER
    form_class= DateForm 
    form = form_class(request.POST or None)
    if request.method=='POST':
    #checks validity of the form
        if form.is_valid():
            return HttpResponseRedirect(reverse('welcome.html'))
    return render(request, 'welcome.html', {'form':form})


welcome.html



 **

{%  extends 'base.html' %}

    {% block content %}
    <title>welcome</title>

        <form action = "{% url "imarket"}" method = "POST">
            {% csrf_token %}
            <table>
                {{form}}
            </table>
            <input type ="submit" value= "CHECK"/>
        </form>

    {% endblock %}

** 我想在欢迎页面上实现一个datepicker, 我在views.py中调用了表单,并返回了&#34; welcome.html&#34;文件在视图中,但是当我转到欢迎页面时,我仍然会看到一个空白页面

我正在使用django版本1.11.2 任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

reverse()函数接受url名称空间,而不是html模板。也许试试这个:

return TabBar(
  indicator: BoxDecoration(
      color: Colors.blue,
      borderRadius: const BorderRadius.all(
        const Radius.circular(999.0),
      ),
      boxShadow: const [BoxShadow(color: Colors.blueAccent, blurRadius: 6.0)]
  ),
  unselectedLabelColor: Colors.blue,
  labelColor: Colors.white,
  isScrollable: true,
  tabs: tabs,
);