这两天着手完成了师哥安排的相关资讯模块的前台显示后台数据库信息,感受到从UI设计到改善功能的开发流程。最大的感触就是,有一个专门进行UI设计的队员是必不可少的。
此次的相关资讯界面设计由正姐完成了,然后把界面的仓库拉到我的本地,来找到我所需要的界面,再在主项目的前台界面里面开始进行编码设计。所以,我觉得主要完成的就是路由视图里面与数据库的链接。举个例子:
相关资讯的主页界面样式就用正姐设计好的,我修改的地方就是从views层里面得到数据信息显示的地方
@bp.route('/list', methods=['GET','POST'])
@login_required
def consult_list():
consults=ConsultDoc.objects.all()
for con in consults:
if con.category.parent.category==u'行业动态':
hid=con.category.parent.id
return tmpl(consults=consults,hid=hid)
比如这里就一是找到所有的数据库信息,二是提取需要的数据
<ul class="new1-list">
{% for consult in consults %}
{% if consult.category.parent.category == "行业动态" %}
<li class="new1-list-conter1"><a href="{{ url_for('consult.consult_detail',id=consult.id) }}">{{ consult.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
以上的就是在html模版里面进行数据库信息的显示
<p><strong><span></span> 行业动态</strong><a href="{{ url_for('consult.consult_more',id=hid) }}" class="more">更多</a></p>
同样提取需要的数据也是这样使用即可,基本就是页面跳转会用。
小问题都是关于页面显示等问题,解决的办法经由寻找有:
1.如何显示部分开头信息?用
<p style="width:100px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">xxxxxxxxxxx</p>
设置style里的属性即可
2.富文本存入数据库的数据为html格式,如何在页面显示非html格式?
<p>
{{ consult.body|safe }}
</p>
safe可以解决此问题
最后说的问题是关于数据库表属性使用的问题,主要这里使用的是mongodb
@bp.route('/more/<id>', methods=['GET','POST'])
@login_required
def consult_more(id):
page = request.args.get('page', 1, type=int)
pagination = ConsultDoc.objects.paginate(page,
per_page=current_config.PAGE_SIZE,
error_out=False)
cate=ConsultCategoryDoc.objects.get_or_404(id=id)
print cate.id,cate.category
category=ConsultCategoryDoc.objects(parent=cate.id)
for m in category:
print "行业动态的三个",m.id
consults=[]
for m in category:
consult=ConsultDoc.objects(category=m.id)
for c in consult:
consults.append(c)
for c in consults:
print "测试",c.title
return tmpl(consults=consults,pagination=pagination)
这就是问题解决的过程,print手动测试是笨办法。
这块当时主要的问题是,id一直都找不对,看见parent=cate.id没,就是要迈过这个坎,此处的parent居然是一个id,嗯之前是知道的,在
mongobooster的这块查看确实是的。
其实在后台数据管理那块我是都知道的。问题是,
在文章的表中category = mongo.ReferenceField(ConsultCategoryDoc)的category是consultcategory的某对象,所以一定要明确两个的id代表什么。