Brief for Django using 2

Firstly we create a new app and then we are going to learn something about parameter transferring.

Functions in views.py can take more than one parameter, though, they have to be named, whose name will be used in HTML templates, URLs and URL configure files.

take this function for example.

from django.http import HttpResponse
def index(request, count):
 return HttpResponse(count)

This 'count' should also appear in its path in urls.py where its type should also by clarified.

In paths, the parameter should be written like 'blahblah/<int:count>', just like the format function but {s are taken place by <s.

This can also work in a template's tags' srcs or hrefs.

For example,

<a href="{% url 'urlname' parameter %]">hahaha</a>

From here we can see the importance of a urlname which is assigned in paths, like 

urlpatterns = [
    path('<int:parameter>/index', views.index, name='index'),

If you have more than one app in your project, you may want to namespace your urlpatterns. You can just add app_name in urls.py, and when it's been included the HTML templates' soft-coded url can use it like below.

<a href="{% url 'app_name:urlname' parameter %}">heiheihei</a>

------------------------------------------------------------------------------------------------------------------------------------------------------------


Next we are going to talk about functions about templates a little, and it will be just the shortcuts, so if you want to see it wholly, you should after read Django's official documents.

#rendering a template
from django.shortcuts import render
...
return render(request,'appname/iddd.html',{addtional_parameter_dict_used_by_html_template_engine})
...
Django will look up the app's "template" directory and find the path you gave it, and then pass the parameter dict to that html template and return it as if it's a HttpResponse.


use {{ obj_name }} to show the object in a html template.

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
And like Python, there is also something like "for" loop or "if else endif", which are being translated later into HTML.

In the end we are about to talk some heads-up when it comes to databases.

Logically, when you are accessing a webpage whose back-end can access databases, you are looking for something in that particular database, whose result can be "misson accomplished" or "404 not found".

You can use a shortcut in Django like get_object_or_404.

from django.shortcuts import get_object_or_404
...
question = get_object_or_404(Question,pk=question_id)
return render(request, 'question/details.html', {'question':question})
...



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BRIEF算法是一种特征描述子提取算法,它可以在MATLAB中实现。BRIEF算法的主要思想是以特征点为中心,取一个大小为S x S的区域,并对该区域进行高斯平滑处理。然后,通过计算区域内的像素对的亮度差异,并将结果编码为一个维度为N的位字符串,即特征点的描述子。BRIEF算法的优点是提取代价低,匹配只需要使用简单的汉明距离计算,时间代价低,空间代价低,并且效果还不错。因此,它在图像处理和计算机视觉领域中得到了广泛的应用。\[2\]\[3\]如果你想在MATLAB中实现BRIEF算法,可以参考相关的文章和资料。 #### 引用[.reference_title] - *1* [matlab练习程序(BRIEF描述子)](https://blog.csdn.net/weixin_34571341/article/details/115970632)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [特征描述子算法——BRIEF](https://blog.csdn.net/Williamcsj/article/details/121291878)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [什么BRIEF算法?BRIEF算法详解](https://blog.csdn.net/qinge_Crazy/article/details/119253418)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值