Django URLField and HTML5?

Is it possible to make django (v1.2) URLField output an HTML5 tag input, where type="url"?

------------- DECISION -------------

from django.forms import ModelForm
from django.forms import widgets
from django.forms import fields
from models import MyObj

class URLInput(widgets.Input):
    input_type = 'url'

class MyObjForm(ModelForm):
    url = fields.URLField(widget=URLInput())

    class Meta:
        model = MyObj
+3
source share
1 answer

To do this, you need to create your own widget.

class URLInput(forms.TextInput):

    input_type = 'url'

You can then pass this widget to the URLField constructor:

class MyForm(forms.Form):

    url = forms.URLField(widget=URLInput())
+3
source

Source: https://habr.com/ru/post/1759371/


All Articles