Date:2016-11-10
By:Black Crow
前言:
本次作業(yè)為第四周第一節(jié)作業(yè)。
操作步驟不少,會出現(xiàn)各種各樣的問題,一開始會需要都花時間調(diào)試。
期間在stackoverflow查了好多問題,總算是把問題給解決了。
作業(yè)效果:
blog.png
大致操作步驟圖(視頻步驟較多,大致記了一下):
Django搭建流程.png
我的代碼:
part1:urls.py中需要注意導(dǎo)入
from django.conf.urls import url
from django.contrib import admin
from blog import views
#pycharm里顯示會有問題,一開始總以為有問題
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/', views.index),#這是之前按照教程視頻做的時候添加的index頁面
url(r'^blog_index/', views.blog_index),#本次blog的頁面
part2:views.py中需要注意不要漏了return,否則會報錯
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'index.html')#一定不要漏了return
def blog_index(request):
return render(request,'blog_index.html')#本次blog里的
part3:setting.py中需要注意templates的dirs和staticfile_dirs
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates'),],#逗號什么的不要漏了
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATICFILES_DIRS =(os.path.join(BASE_DIR,"static"),)#逗號什么的不要漏了```
>#####part4:html中需要注意tag的書寫格式,實測空格什么的會有影響,可以自己試一下。另css中有引用圖片的url的(第一周第一節(jié)的css里就有鏈接背景圖的),會顯示不出,暫時還沒查如何表述比較好
{% load static %} #這是tag
body {
padding: 0 0 0 0;
background-color: #ffffff;
background-image: url(images/bg3-dark.jpg);#第一周第一節(jié)課提供的css素材中就引用了背景圖,但是按照視頻操作的時候這個背景是沒有顯示出來的。
background-position: top left;
background-repeat: no-repeat;
background-size: cover;
font-family: Helvetica, Arial, sans-serif;
}
####總結(jié):
>1. pycharm用的是社區(qū)版緣故,所以采用的是課程里提供的另外一個教程來配置虛擬環(huán)境
https://djangogirlstaipei.gitbooks.io/django-girls-taipei-tutorial/content/django/installation.html ,教程的內(nèi)容很有幫助。
2. 還是得對著教程來一遍才印象深刻,坑還是有,盡量得跳出來。

