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: ianitiandf_goodsmodels.py", line 2, in <module>
    from DjangoUeditor.models import UEditorField
  File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesDjangoUeditormodels.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),点击下载(内附教程)
原文地址:https://www.cnblogs.com/ftl1012/p/10388755.html