多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
本地调试添加静态文件目录 ~~~ STATIC_URL = '/static/' #添加静态文件目录 STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) ~~~ web服务器上线需要收集静态文件 `python manage.py collectstatic` 修改settings静态文件 ~~~ STATIC_URL = '/static/' #服务器收集静态文件至static STATIC_ROOT = os.path.join(BASE_DIR, 'static') ~~~ 静态文件引入 ~~~ {% load staticfiles %} {% static '/static/css/style.css' %} ~~~ 文件继承 ~~~ {% extends "base.html" %} {% block title %} {% endblock %} {% url 'account:user_logout' %} ~~~ URL配置 app url ~~~ from django.conf.urls import url #引入app项目 view from .import views urlpatterns = [ url(r'^$', views.user_login, name="user_login"), url(r'^blog/$', views.user_login, name="blog"), url(r'(?P<pk>[0-9]+)/$', views.chanpin_names, name="chanpin_names"), ] ~~~ 项目url ~~~ from django.conf.urls import url, include import xadmin urlpatterns = [ url(r'^xadmin/', xadmin.site.urls), url(r'^login/', include('users.urls', namespace='login')), ] ~~~ views 获取数据 `.order_by('-id') 数据排序` ~~~ #导航 def Fengg(request): chanpinx = chanpin.objects.all().order_by('-id') fenggx = fengg.objects.all() qyx = qy.objects.all() sxx = sx.objects.all() return render(request, 'best1/best.html', {"chanpinx": chanpinx, "fenggx": fenggx, "qyx": qyx, "sxx": sxx}) #风格分类 def chanpin_names(request, pk): #pk传入fengg数据 cate = get_object_or_404(fengg, pk=pk) #fengg 为chanpin数据表ForeignKey所对应数据 #filter 筛选数据 post_list = qyfl.objects.filter(title=cate) #导航分类 fenggx = fengg.objects.all() qyx = qy.objects.all() sxx = sx.objects.all() return render(request, 'best1/cp.html', {"post_list": post_list, "fenggx": fenggx, "qyx": qyx, "sxx": sxx}) ~~~ HTML 引入数据 URL: ``{% url 'jp:fengg' %}`` 数据:``{{ fg.title }}`` for循环:``{% for fg in fenggx %} {% endfor %}``