Django電商項目---完成商品主頁顯示day2


利用DjangoAdmin初始化數據庫

  • 創建項目

python manage.py startapp df_goods

image

  • 添加配置

manas/urls.py

image

manas/settings.py

image

新創建文件df_goods/urls.py

image

  • 安裝富文本編輯器

   博主的Ueditor文件(來源github上修改好的版本DjangoUeditor3),點擊下載(內附教程)

  • 配置富文本編輯器

Django學習---py3下的富文本編輯器的使用

  • 配置靜態文件上傳路徑
  1. 創建upload目錄(跟manage.py在同一目錄下)

image

  1. 配置文件訪問路徑:manas/settings.py

image

  1. 配置路由路徑: manas/urls.py

image

  • 添加靜態文件夾

templates/df_goods

image

  • 配置models.py

image

  • 初始化數據庫
python manage.py makemigrations
python manage.py migrate

  • 配置Django Admin信息

df_goods/admin.py

image

  • 創建Django admin賬戶
python manage.py createsuperuser

image

  • 啟動項目:
python manage.py runserver 8888
  • admin賬戶登錄

image

  • 添加數據信息

image

  • 完成Django靜態文件的模板繼承: templates/df_goods

image

 

商品頁面顯示

  • 需求一: 完成頁面數據的顯示

df_goods/views.py

image

df_goods/urls.py

image

templates/df_goods/index.html

image

頁面展示:

image

 

點擊圖片,跳轉詳情頁面

df_goods/views.py

image

df_goods/urls.py

image

templates/df_goods/detail.html

image

編寫JS文件用於計算總價(稍有問題):

templates/df_goods/detail.html

image

  • 界面展示

image

 

詳情頁面跳轉商品分類頁面

點擊跳轉

image

df_goods/views.py

image

df_goods/urls.py

image

templates/df_goods/list.html

image

image

頁面展示(根據價格實現倒序):

image

 

完成分類商品頁面的分頁效果

安裝Paginator

image

進行商品分類

df_goods/views.py

image

templates/df_goods/list.html

image

image

頁面效果

image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

問題記錄

問題詳細: 
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),點擊下載(內附教程)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM