首页 > 解决方案 > Datetimepicker 和 DJANGO 无法正确加载

问题描述

为了了解发生了什么,我一直在发疯,但我似乎无法弄清楚问题所在。它只发生在生产中,而不是在开发服务器中。这是我的配置:

设置.py

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static")
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

base.html(布局即时扩展)

<!DOCTYPE html>
<html lang="en">

{% load static %}

{% load bootstrap4 %}

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>WHARFY</title>
  {% bootstrap_javascript jquery='full' %}
  {% bootstrap_css %}

  <!-- Custom fonts for this template-->
  <link href='{% static "vendor/fontawesome-free/css/all.min.css"%}' rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

  <!-- Custom styles for this template-->
  <link href='{% static "css/sb-admin-2.min.css" %}' rel="stylesheet">

model_update.html(我正在使用 UpdateView)

{% extends 'base.html' %}
{% load bootstrap4 %}

{% block content %}

{{ form.media }}

<form method="post">{% csrf_token %}
  {% bootstrap_form form %}
  <input type="submit" value="Save">
</form>
{% endblock %}

虽然在开发中我没有任何问题,但在生产中我从控制台收到此错误

Failed to load resource: the server responded with a status of 404 (Not Found)
datepicker-widget.css:1

Failed to load resource: the server responded with a status of 404 (Not Found)
datepicker-widget.css:1 

日期时间选择器不显示(仅在生产中)

我使用 datetimepicker plus 和 bootstrap 正确安装并成功运行以下命令:

python manage.py collectstatic

我是 django 的新手,我发现了类似的问题,但不知道如何使它工作。

标签: djangopython-3.xdjango-formsdjango-viewsdjango-templates

解决方案


推荐阅读