django制作简单网页
- pycharm,新建project,选择django
打开terminal
python manage.py startapp myapp
myapp文件夹右键新建文件夹:template,在此文件夹下新建about.html,contact.html,home.html
其中的home.html:
{% block content %}
<nav>
<ul>
<li>首页</li>
<li>关于</li>
<li>联系</li>
</ul>
</nav>
<h1>欢迎访问我的网站!</h1>
<!-- 其他首页内容 -->
{% endblock %}
views.py:
from django.shortcuts import render
def home(request):
return render(request, 'home.html')
def about(request):
return render(request, 'about.html')
def contact(request):
return render(request, 'contact.html')
diangoProject文件夹下的urls.py
from django.urls import path
from myapp import views
urlpatterns = [
path('', views.home, name='home'),
path('about/', views.about, name='about'),
path('contact/', views.contact, name='contact'),
]
在setting.py中加上这两个
最后运行:
标签:about,网页,request,django,html,contact,home,制作 From: https://www.cnblogs.com/y0uth/p/17863284.html