django連線資料庫和靜態資源配置
帶有條件查詢
filter
xclude
排序查詢:
order_by()
分頁
[:]
html django標籤
如何使用標籤
{%csrf_token%}
{%ul%}
{%for%}{%endfor%}
{%if%} {%else%} {%endif%}
---------------------------------------------------------------------------------modelForm
form-->Model
通過繼承ModelFoem,編寫其中的內部類
class Meta:
model=Student
fields
exclude
多選:MultipleChoiceField
檔案上傳:
form.FileField(upload_to="upload")手動處理
model.FileField(upload_to)這個用在自動儲存上傳檔案
上傳是ModelForm中必須傳入request.FILES
urlCONF
檢視
不使用django.contrib.staticfiles模組時,可以利用django.views.static.serve提供靜態資源。用法簡單,只要在urls.py使用下面的程式碼,一般除了開發時有靜態資源,其他是不讓寫靜態資源的:
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL
MEDIA_URL='/upload/')
settings.py
MEDIA_ROOT=os.path.join(BASE_DIR,"upload")
MEDIA_URL='/upload/'
shop頁面管理
urls.py
MEDIA_ROOT=os.path.join(BASE_DIR,"upload")
MEDIA_URL='/upload/'
settings.py
STATICFILES_DIRS=(
os.path.join(BASE_DIR,"static")
)
連線mysql資料庫
下載資料庫:pip install
mysqlclient
settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': "shopsys_db", 'HOST':"localhost", 'USER':"root", 'PASSWORD':"root", 'PORT':"3306" } }
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'goods',//把名字導過來 ]
makemigrations 資料庫名goods下的migrations下會有一個0001的檔案
然後sqlmigrate資料庫名稱 0001把資料庫遷移
頁面載入建立一個static資料夾 把easyui導進來