Django---渲染到模板

简单的路由操作:

from index import views
urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/', views.index),
]

index应用下的 views 文件进行输出到模板方法:

第一步:template新建 index.html

第二步:方法里面使用render就可以

第三步:模板中如何引入静态资源

1、根目录新建 static 目录

2、settings最后一行做配置

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR,'static'),
)

3、模板里引入

<link rel="stylesheet" href="/static/index.css">

猜你喜欢

转载自www.cnblogs.com/e0yu/p/9491985.html