def foo_view(request):
return render(request, 'foo_tpl.html', {'is_error': False})
{% if is_error %}
shit happens
{% endif%}
class ArticleDetailView(DetailView):
model = Article
template_name = "articles/article.html"
class ArticleDetailAddLikeView(ArticleDetailView):
def get_object(self):
object = super(ArticleDetailAddLikeView, self).get_object()
object.article_likes += 1
object.save()
return object
Какой фронтэнд для скрипта выбрать?
The Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Цель:напротив - тебе нужно максимум передать в бд пусть сама разруливает
Меньше обращений к БД, быстрее обрабатывается файл, меньше нагрузка на железо
@transaction.atomic
def do_stuff():
# This code executes inside a transaction.
user_id = models.IntegerField()
id_post= models.IntegerField()
{% if one_post.pk in all_likes.id_post %}
# views.py
liked_post_ids = UserLikes.objects.filter(user=request.user).values_list('id', flat=True)
# template.html
{% if post.id in liked_posts_ids %}
This post was already liked.
{% else %}
You can like this post.
{% endif %}
# models.py
from django.contrib.auth.models import User
from django.db import models
class Post(models.Model):
user = models.ManyToManyField(User)
slug = models.SlugField()
системы (веб сервис), которая должна выдерживать высокие нагрузки и быть масштабируемой.
достаточно быстро функционал и следовательно посещаемость (по прогнозам - я за это не отвечаю, предо мной просто ставят такую задачу) буду увеличиваться.
Насколько такой вариант будет выдерживать высокие нагрузки?
насколько будет быстро работать, учитывая динамическую типизацию