终于搞定了
forms.py - 几乎不言自明
import datetime
from django import forms
from django.forms import widgets
from django.contrib.admin import widgets
from .models import cert
class CertForm(forms.ModelForm):
class Meta:
model = cert
fields = '__all__'
widgets = {
'created_date': widgets.AdminDateWidget,
'expiry_date': widgets.AdminDateWidget,
}
urls.py -
from django.urls import path
from django.views.i18n import JavaScriptCatalog # **add this**
from . import views
urlpatterns = [
path('', views.cert_list, name='cert_list'),
path('cert/<int:pk>/', views.cert_detail, name='cert_detail'),
path('cert/new', views.cert_new, name='cert_new'),
path('jsi18n', JavaScriptCatalog.as_view(), name='javascript-catalog'), # **add this**
]
base.html 模板添加这个块
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script type="text/javascript" src="{% static '/admin/js/core.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static '/admin/css/widgets.css' %}">
<style>.calendar>table>caption{caption-side:unset}</style>
{{ form.media }}
即
% load static %}
{% load admin_static %}
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/base.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/widgets.css' %}" />
<html>
<head>
<title>SSL Cert Management</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{% static 'css/cert.css' %}">
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script type="text/javascript" src="{% static '/admin/js/core.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static '/admin/css/widgets.css' %}">
<style>.calendar>table>caption{caption-side:unset}</style><!--caption fix for bootstrap4-->
{{ form.media }}
</head>
<body>
<div class="page-header">
<a href="{% url 'cert_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
<h1><a href="/">SSL Cert Management</a></h1>
</div>
<div class="content container">
<div class="row">
<div class="col-md-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>