1.从数据库中读取数据时可以用filter多条选择,(例如所有只有经过审核通过的才可以读取出来,在读取的时候就将结果一次性读取成功,而不是读完数据后再对数据进行处理)
2.在html中的链接书写格式:
<a href="{% url 'publish_news'%}"></a>
<a href="{% url 'publish_news'%}?type={{ t.id }}"></a>
<a href="{% url 'publish_newscontent' new.id %}"></a>(获取参数)
3.同一页面对相应的信息进行筛选显示时 url(r'^news/$', views.news, name="publish_news"),
def news(request,template_name="publish/new-nav.html"):
ctx={}
# 接收参数
type = request.GET.get('type', '')如果接受参数则显示type,否则显示空
if type:
results = News.objects.filter(new_type=type).filter(examine=True)双重filter
else:
results=News.objects.all().filter(examine=True)
ctx['news'] = results
tp=NewType.objects.all()
ctx['types'] = tp
return render(request,template_name,ctx)
4.获取参数时
url(r'^news/(\d{1,11})/$', views.newscontent, name="publish_newscontent"),
<a href="{% url 'publish_newscontent' new.id %}">
def newscontent(request, newsID, template_name="publish/new.html"):
ctx={}
results = News.objects.get(id=newsID)
if results :
results.update_state_info()
ctx['news'] = results
if results :
ctx['next'] = results.get_next_news()
ctx['previous'] = results.get_previous_news()
tp = NewType.objects.all()
ctx['types'] = tp
re = News.objects.filter(examine=True).order_by('time_born')[0:9]
ctx['nums'] = re
return render(request, template_name, ctx)
5.页面中的变量数据显示为html格式时可以用js控制:
<div id="news-abstract">{{news.abstract}}</div>
<script type="text/javascript">
$(function(){
$('#news-content').html(htmlDecode($('#news-content').html()));
$('#news-abstract').html(htmlDecode($('#news-abstract').html()));
});
</script>
6.在使用瀑布流时,在Google浏览器和IE浏览器中会出现一定的差异,Google计算层的高度会比ie的低,其原因时在加载图片是Google时先显示内容再加载图片,所以最后的计算值会相对小,ie是先计算图片高度,再加载图片,显示的效果正常
http://zhouyj668.blog.163.com/blog/static/11252328020137224830587/
7.在取数据库中的上一条数据和下一条数据,用于从取出的当前数据向前向后取出一个数据
8.在类中定义方法...
今天学习了好多,其中很多问题都是要一个一个解决,决不能含糊,所以以后的应付心里真心的要不了,自己写代码一定要规整,认真,这样才能事半功倍...