Feb. 26, 2019, 10:22 a.m.


SFINAE, C++17, template

There was a problem: "write the second implementation of the template function", in which the same arguments are passed. That is, the signature of both functions completely coincides. The difference is that, as an argument, the std::vector containers and the std::map containers can be passed to the function. And depending on whether std::vector is or std::map, this or that implementation should be selected.

In this case, the SFINAE rule will be used, which states: If the final types of arguments cannot be calculated (to perform substitution of template parameters) of an overloaded template function, the compiler does not throw an error, but searches for another suitable overload. The error will be in three cases:

  • No suitable overload was found.
  • Several such overloads were found, and C ++ cannot decide which one to take.
  • The overload was found, it turned out to be a template, and an error occurred when instantiating the template.

Our case will be the second. There are two overload template functions.

Jan. 28, 2019, 6:19 a.m.


Django, jinja, Python, template

На ресурсе Medium Corporation пользователь под ником Samu делится опытом использования Jinja2. По его словам ранее он использовал Jinja2 в своих проектах, созданных с помощью Flask. Но затем решил использовать Jinja2 с Django для потенциального повышения производительности (в 10-20 раз быстрее по сравнению с шаблонами Django) и взаимодействия с Nunjucks. Samu делится опытом с людьми, которые уже знакомы с данными технологиями, а его статья призвана немного раскрыть и упростить шаги.

Jan. 27, 2019, 4:49 p.m.

Добрый день!

На одной html странице нужно разместить два UpdateView. Для этого имя формы для одного хочу изменить на update_form, а второе на upd_form.

Стандартно в html файле UpdateView для формы использует имя form.

Код формы в html:

<form action="." method="POST">
    {% csrf_token %}
    {{ form.as_p }}
    <button class="btn btn-outline-info" type="submit" value="Save">Add</button>
    <a href="{% url 'home' %}" class="ml-2 mt-2">Cancel</a>

В документации указано что для изменения этого имени нужно указать context_object_name.

Пробовал так (views.py):

class DataUpdateView(LoginRequiredMixin, UpdateView):
    template_name = 'index.html'
    form_class = MyForm
    context_object_name = 'update_form' ###

    def get_object(self):
        return get_object_or_404(Project, id=self.kwargs.get('id'))

    def form_valid(self, form):
        return super().form_valid(form)

    def get_context_data(self, *args, **kwargs):
        context = super(ProjectUpdateView, self).get_context_data(*args, **kwargs)
        data = filter(self.request)
        return context


<form action="." method="POST">
    {% csrf_token %}
    {{ update_form.as_p }}
    <button class="btn btn-outline-info" type="submit" value="Save">Add</button>
    <a href="{% url 'home' %}" class="ml-2 mt-2">Cancel</a>

Не работает. Возможно я что-то не так понял?

Jan. 5, 2019, 2:49 p.m.


templatetags, template, Django

In Django - Lesson 035. Different templates for rendering different types of content in search results it was shown how to render different templates depending on what type of content drawn in the search results on the site. In this case, the key point was that it was not necessary to make the verification conditions for the selection of the template. The information about the balbalon was stored in the variable TEMPLATE_PREVIEW, through which the template was inserted into the include tag in the Django template.

{% include object.TEMPLATE_PREVIEW %}

In this method there is one big drawback. The fact is that the include tag with each of its calls is looking for a template. With a large load on the site - this can significantly increase the duration of the response from the server. To solve this problem, you need to somehow cache the pattern. Since different types of content use different templates, to do this using inclusion_tag is quite problematic.

This problem was solved by caching the template at the class level as a class variable.

Aug. 6, 2018, 6:52 a.m.


template, lambda, C++11

The world of programming in C ++ in the new standards allows us to get up a variety of things, thanks to which we can safely abandon some old statements or principles, or simply flexibly approach these principles.

I would like to outline my view on the work of the RAII idiom and the C ++ 11 standard with respect to one established principle whose authorship is attributed to Edsger Dijkstra :

"The module (in this case the function) must have only one entry point and only one exit point"

For this principle, multiple returns in a function / method are contrary to the principles of structured programming for the following reasons:

  • the complexity of debugging code with the use of multiple returns returns increases with the number of these same return, that is, you never know when the function or method of an object just exited.
    the complexity of code support, when all the points of the call are not visible at the initial look at the function. Also, it is not known whether the code added to the end of the function will execute or not, especially if the program logic should always execute this code. That is, in the case of multiple returns, you will have to implement this code before every call to the return operator.

But modern C ++ has already changed significantly since the times of Dijkstra and the means of the latest C ++ standards allow to bypass or significantly level out the influence of the reasons that caused the formulation of the principles of structured programming.

July 5, 2018, 7:05 a.m.


Django, template, content, Search

Constant visitors of the site who use the search on the site, probably noticed that the display of articles differs from displaying comments in the search engine issue of the site. This was achieved by the fact that each content type has its own template for rendering, which is substituted for the rendering of the page, depending on what content was found in the search.

Let's look at the example of issuance.

You see, here the presentation of the comment differs from the article, but they are output in the framework of one search issue, as was done in the previous article.

But this is done much more elegantly than selecting via if else . Honestly, I myself really like this decision.

Sept. 18, 2016, 7:41 a.m.


view, model, template

In Django uses a modular system of applications, where one application is composed of several applications, each responsible for its functionality. As you have noticed, at the time of this writing, the site has a section "Knowledge", in which there are several sections, which have divided the article.

When working with the previous site on Wordpress, mindlessly spend time on the addition of new articles to the list of lessons on Qt. On this same site the page is automatically generated and save a new article is published with the status, this article will automatically enters the relevant section of the list.

I suggest to understand how it is implemented in a minimal version of the example EVILEG COM.

May 25, 2019, 4:20 p.m.
Андрей Янкович

C++ - Test 001. The first program and data types

  • Result:93points,
  • Rating points8
May 19, 2019, 1:49 a.m.

Qt - Test 001. Signals and slots

  • Result:78points,
  • Rating points2
May 17, 2019, 1:14 p.m.

Qt - Test 001. Signals and slots

  • Result:42points,
  • Rating points-8
Last comments
May 21, 2019, 8:10 p.m.

Приветствую! Я думаю дойдёт и до этого, но пока изучать его у меня нет желания.
May 20, 2019, 7:20 p.m.
Евгений Легоцкой

Добрый день! Вы не думали разместить репозиторий проекта на GitHub?
May 18, 2019, 2:03 p.m.

Спасибо большое! Вскоре буду разбираться!
May 18, 2019, 9:13 a.m.
Евгений Легоцкой

Добрый день! Отнимать значение общего счётчика можно в деструкторе класса кнопки QDynamicButton::~QDynamicButton(){ ResID--;} При этом я бы ещё переустанавливал значения вс...
May 14, 2019, 10:33 p.m.

Здравствуйте!А не подскажите, как можно при удалении какой либо кнопки, у щётчика отнять значение?Дабы например четвёртой кнопке соответствовал ID 4, а не 5 скажем
Now discuss on the forum
May 24, 2019, 6:48 a.m.
Евгений Легоцкой

Если там будут только перечисления внутри namespace, то жа, достаточно будет заголовочного файла
May 24, 2019, 6:28 a.m.
Андрей Янкович

работает любой http сервер, и можно использовать обсалютно любой портпример <RemoteRepositories> <Repository> <Url>;
May 23, 2019, 2:40 p.m.

Попробовал сделать этот запрос по http и получил json файл. request.setUrl(QUrl("https://jsonplaceholder.typicode.com/todos/1")); Как Вы думаете, почему https не работает и как это и...
May 23, 2019, 10:42 a.m.

Спасибо, помогло.
May 23, 2019, 6:31 a.m.
Евгений Легоцкой

Для задач и граф-то не нужен. Достаточно будет таблицы в локальной базе данных SQLite, в которой указывается задача, время и т.д. В этом разделе есть примеры по работа с базой д...

For registered users on the site there is a minimum amount of advertising

Join us
© EVILEG 2015-2019
Recommend hosting TIMEWEB