静态文件不存在且 html-文件无法正常工作
Static file doesn't exist and html-file doesn't work properly
输出:
'static' in the STATICFILES_DIRS setting does not exist.
我试过 os.path.join(BASE_DIR, '/static'),但它不起作用。在添加新的 html-file 之前我没有遇到这个问题,而且我没有更改静态文件夹。 Setting.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
我在静态文件夹中放置了文件夹 'main' 和 css 文件。 base.html
我的文件也有问题。它不能正常工作。估计是我没接好。
<a href="{% url 'make_vision' %}"><li><button class="btn btn-info"><i class="fas fa-plus-circle"></i>Добавить запись</button></li></a>
make_vision.html
{% extends 'main/base.html' %}
{% block title %}Добавление записей{% endblock %}
{% block content %}
<div class="features">
<h1>Форма по добавлению статьи</h1>
<form method="post">
<input type="text" placeholder="Название статьи" class="form-control"><br>
<input type="text" placeholder="Анонс статьи" class="form-control"><br>
<textarea class="form-control"><br>
<input type="date" class="form-control"><br>
<button class="btn btn-success" type="submit">Добавить статью</button>
</form>
</div>
{% endblock %}
urls.py
urlpatterns = [
path('', views.news_home, name='news_home'),
path('make_vision', views.make_vision, name="make_vision"),
]
views.py
def news_home(request):
news = Articles.objects.order_by('-data')[:2]
return render(request, 'news/news_home.html', {'news': news})
def make_vision(request):
return render(request, 'news/make_vision.html')
当我启动服务器时,出现此路径不存在的错误。
这样做:
settings.py:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
urls.py:
urlpatterns = [
path('', views.news_home, name='news_home'),
path('make_vision', views.make_vision, name="make_vision"),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
在模板中:
make_vision.html:
{% extends 'main/base.html' %}
{% load static %}
{% block title %}Добавление записей{% endblock %}
{% block content %}
<div class="features">
<h1>Форма по добавлению статьи</h1>
<form method="post">
<input type="text" placeholder="Название статьи" class="form-control"><br>
<input type="text" placeholder="Анонс статьи" class="form-control"><br>
<textarea class="form-control"><br>
<input type="date" class="form-control"><br>
<button class="btn btn-success" type="submit">Добавить статью</button>
</form>
</div>
{% endblock %}
输出:
'static' in the STATICFILES_DIRS setting does not exist.
我试过 os.path.join(BASE_DIR, '/static'),但它不起作用。在添加新的 html-file 之前我没有遇到这个问题,而且我没有更改静态文件夹。 Setting.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
我在静态文件夹中放置了文件夹 'main' 和 css 文件。 base.html
我的文件也有问题。它不能正常工作。估计是我没接好。
<a href="{% url 'make_vision' %}"><li><button class="btn btn-info"><i class="fas fa-plus-circle"></i>Добавить запись</button></li></a>
make_vision.html
{% extends 'main/base.html' %}
{% block title %}Добавление записей{% endblock %}
{% block content %}
<div class="features">
<h1>Форма по добавлению статьи</h1>
<form method="post">
<input type="text" placeholder="Название статьи" class="form-control"><br>
<input type="text" placeholder="Анонс статьи" class="form-control"><br>
<textarea class="form-control"><br>
<input type="date" class="form-control"><br>
<button class="btn btn-success" type="submit">Добавить статью</button>
</form>
</div>
{% endblock %}
urls.py
urlpatterns = [
path('', views.news_home, name='news_home'),
path('make_vision', views.make_vision, name="make_vision"),
]
views.py
def news_home(request):
news = Articles.objects.order_by('-data')[:2]
return render(request, 'news/news_home.html', {'news': news})
def make_vision(request):
return render(request, 'news/make_vision.html')
当我启动服务器时,出现此路径不存在的错误。
这样做: settings.py:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
urls.py:
urlpatterns = [
path('', views.news_home, name='news_home'),
path('make_vision', views.make_vision, name="make_vision"),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
在模板中: make_vision.html:
{% extends 'main/base.html' %}
{% load static %}
{% block title %}Добавление записей{% endblock %}
{% block content %}
<div class="features">
<h1>Форма по добавлению статьи</h1>
<form method="post">
<input type="text" placeholder="Название статьи" class="form-control"><br>
<input type="text" placeholder="Анонс статьи" class="form-control"><br>
<textarea class="form-control"><br>
<input type="date" class="form-control"><br>
<button class="btn btn-success" type="submit">Добавить статью</button>
</form>
</div>
{% endblock %}