Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

How to modify the form field types in the django CreateView form

I have a model that has a couple of date fields. I am using the CreateView along with a template. In the template, I am doing fairly standard code

{% extends 'instructor_base.html' %}
{% load crispy_forms_tags %}

{% block title %}
    New Section
{% endblock %}

{% block content %}
    <h1>New Section</h1>
    <form method="post">
        {% csrf_token %}
        {{ form|crispy }}
        <button class="btn btn-success ml-2" type="submit">Save</button>
    </form>
{% endblock %}

However, when the form displays, the two date fields in the model are displayed as text boxes in the form. I would like them to display as date type. After several hours of going through documentation and tutorial sites, I can not figure out how to accomplish this. Everything I find is on how to override CreateView itself and not the form that goes with it. Any help with this would be greatly appreciated.

question from:https://stackoverflow.com/questions/65652203/how-to-modify-the-form-field-types-in-the-django-createview-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...