我创建了一个nav.html模板,css.html模板和js.html模板。然后我使用include模板标记将它们呈现在我的base.html模板中。
(nav.html)
{% load staticfiles %}
<div class="container-fluid">
<nav class="navbar navbar-dark bg-primary py-1">
<a class="navbar-brand mb-0 h1" href="#">
<img src="{% static 'profiles/logo.png' %}" width="30" height="30" class='d-inline-block align-top' alt=""/>Hot-Minet Services Ltd
</a>
</nav>
</div>
(css.html)
link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
(js.html)
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
(base.html)
{% load staticfiles %}
<!Doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{% include "snippets/css.html" %}
<title>{% block title %}My amazing site{% endblock %}</title>
</head>
<body>
{% include "snippets/nav.html" %}
<br>
{% block form %}
<div class="container">
<div class="row justify-content-md-center">
<div class="col-sm-6">
<form action="" method="POST">{% csrf_token %}
{{ form.as_p }}
<button type="button" class="btn btn-primary btn-lg">Save</button>
</form>
</div>
</div>
</div>
{% endblock %}
{% include "snippets/js.html" %}
</body>
</html>
(home.html)
{% extends "base.html" %}
{% block form %}
<div class="container">
<div class="row justify-content-md-center">
<div class="form-group col-sm-4">
<form action="/update/slug/" method="GET">
<input class="pt-3 form-control" type="text" name="" value="" placeholder="Type client name here"/>
<br>
<input class="btn btn-primary pt-2 mb-5" type="submit" value="Update"/>
</form>
</div>
</div>
</div>
{% endblock %}
(settings.py)
STATIC_URL = '/static/'
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static' 'static-alone')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static' 'media')
STATICFILES_DIR = [
os.path.join(BASE_DIR, "static" 'profiles'),
]
(urls.py)
from django.conf.urls import url, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from profiles.views import(
home,
SendMail,
Add,
resultsPageView,
profileUpdate,
)
urlpatterns = [
#
# Examples:
# url(r'^$', 'myproject.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/',admin.site.urls),
url(r'^home/',home),
url(r'^SendMail/', SendMail.as_view(), name='SendMail'),
url(r'^Add/', Add.as_view(), name='Add'),
url(r'^results/', resultsPageView.as_view(), name='results'),
url(r'^update/(?P<slug>[\w-]+)/$', profileUpdate.as_view(), name='update'),
]
if settings.DEBUG:
urlpatterns +=static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
一切正常,但导航栏上的徽标无法显示,这可以表明有人在这里做错了。