添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
温柔的大葱  ·  Xamarin Forms: How to ...·  3 周前    · 
年轻有为的山羊  ·  How to inject random ...·  2 周前    · 
坚强的猴子  ·  How to create a ...·  3 天前    · 
善良的莴苣  ·  Solved: Query/issue ...·  4 月前    · 
鬼畜的水龙头  ·  Why are new ...·  4 月前    · 
英俊的针织衫  ·  A standardized method ...·  4 月前    · 
重感情的手术刀  ·  ldap_sasl_interactive_ ...·  5 月前    · 
风流的奔马  ·  2024年 Java ...·  6 月前    · 
products = random.sample(products, 9) return render(request, 'front-page.html', {'products': products}) It's actually as simple as this!
First we import random from Python. Then we create a new view and get products from the database. The function we use for randomizing the products only works with lists, so we need to convert the queryset to a list. A queryset is by default a dictionary. When we have the list, we can randomize this by running "random.sample". We pass in the list and the number of products we want.

Build an e-commerce using Django

Want to learn how to build an e-commerce from scratch using Django?

Check out the playlist on my YouTube channel here: https://www.youtube.com/watch?v=bAG_Ia8LX-M&list=PLpyspNLjzwBmIDrDOaPkLLuy5YDDNW9SA

Code With Stein

Learn how to build web sites and web applications using technologies like Django, Vue, Htmx, Tailwind, Bulma and many more.

YouTube Twitter Discord Patreon