利用DjangoAdmin初始化數據庫
- 創建項目
python manage.py startapp df_goods
- 添加配置
manas/urls.py
manas/settings.py
新創建文件df_goods/urls.py
- 安裝富文本編輯器
博主的Ueditor文件(來源github上修改好的版本DjangoUeditor3),點擊下載(內附教程)
- 配置富文本編輯器
- 配置靜態文件上傳路徑
- 創建upload目錄(跟manage.py在同一目錄下)
- 配置文件訪問路徑:manas/settings.py
- 配置路由路徑: manas/urls.py
- 添加靜態文件夾
templates/df_goods
- 配置models.py
- 初始化數據庫
python manage.py makemigrations python manage.py migrate
- 配置Django Admin信息
df_goods/admin.py
- 創建Django admin賬戶
python manage.py createsuperuser
- 啟動項目:
python manage.py runserver 8888
- admin賬戶登錄
- 添加數據信息
- 完成Django靜態文件的模板繼承: templates/df_goods
商品頁面顯示
- 需求一: 完成頁面數據的顯示
df_goods/views.py
df_goods/urls.py
templates/df_goods/index.html
頁面展示:
點擊圖片,跳轉詳情頁面
df_goods/views.py
df_goods/urls.py
templates/df_goods/detail.html
編寫JS文件用於計算總價(稍有問題):
templates/df_goods/detail.html
- 界面展示
詳情頁面跳轉商品分類頁面
點擊跳轉
df_goods/views.py
df_goods/urls.py
templates/df_goods/list.html
頁面展示(根據價格實現倒序):
完成分類商品頁面的分頁效果
安裝Paginator
進行商品分類
df_goods/views.py
templates/df_goods/list.html
頁面效果
問題記錄
問題詳細:
model.py里面使用了富文本編輯器,在執行python manage.py makemigrations的時候報錯如下,
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "F:\tianitian\df_goods\models.py", line 2, in <module>
from DjangoUeditor.models import UEditorField
File "C:\Users\Administrator\AppData\Roaming\Python\Python35\site-packages\DjangoUeditor\models.py", line 4, in <module>
from widgets import UEditorWidget,AdminUEditorWidget
ImportError: No module named 'widgets'
問題定位:
Ueditor HTML編輯器是百度開源的HTML編輯器,但是在Python3下調用報錯,找不到widgets模塊,經查發現,DjangoUeditor是基於Python 2.7的,對Python3的支持有問題。導致widgets.py文件出錯,不能import。
解決方法:
使用博主的Ueditor文件(來源github上修改好的版本DjangoUeditor3),點擊下載(內附教程)