Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
Jan. 5, 2017, 12:47 p.m.


Django, templatetags, Python, список популярных статей

The site already had an article about the withdrawal the list of popular articles in the last 7 days . But in the variant that is used in this article shows how to draw a conclusion on the Articles page. But there was a question as to quickly implement a list of popular articles on any page of the site.

I have solved this problem by using its own tag , which can be used in a Django template. That is, instead of each View on the site to register the same code to obtain a list articles or the use of the same function in this View, I just did a single template with a finished layout for a list of popular articles, which uses my custom tag, which I take a list of these articles. Thus, you only need to implement this pattern in the right place in the page template using the include tag.

Dec. 30, 2016, 5:30 a.m.


referer, Django, IP, HTTP

Obtaining the user IP-addresses from the request on the Django can be useful for the organization of a functional site, such as the hosts lock, from which users are trying to make password brute force to the site or if you need to remember user IP, to provide access to the site for a particular user with only certain IP address.

The IP address can be either real or transmitted through a proxy server (in this case will be transferred HTTP_X_FORWARDED_FOR header which you can extract the real IP address).

def get_client_ip(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[-1].strip()
        ip = request.META.get('REMOTE_ADDR')
    return ip
Nov. 13, 2016, 6:04 a.m.


Django, статистика, популярные статьи

Many blogs and news sites to keep the audience's attention using such methods as ranking popular articles this week, related publications, and some major resources and more advice on user preferences.

First, it was decided to do - it displays a list of popular articles. The first version of the popular articles was based on a general counter views and eventually deduced the article with the most views. This is generally a bad option, since the TOP will result in articles just scored the highest number of views for all time.

Therefore it was necessary to change something. As a result, the output has been introduced popular articles in last 7 days in its simplest form. That is, the table has been added which introduced views of articles by day. Of course, the accuracy of counting under heavy load can vary greatly, but attendance is not reached the 5,000 - 10,000 unique visitors a day - it's not so important.

Now lets proceed with an example of how to make a list of popular articles Django .

Oct. 15, 2016, 1:50 p.m.


контактная форма, Django, контакты

Continuing the development of the site, I would like to share an example of code for adding a contact form on the site to Django. There have already been articles with different shapes, for example, to add comments, but just talking about the entire process as a whole, and we will not get, and this theme party.

Especially that for a site on Wordpress for me it was a pain. Probably, all the fault was laziness, because I did not have any desire to begin to deal with PHP , to sketch out a contact form on their own (as a result of another plugin was used).

And when you consider that the development on the Django , quite often involves working with various forms of data, and thus there is a module for working with e-mail services, and the addition of such a form is not difficult.

Sept. 30, 2016, 4:42 p.m.


Django, MaterializedPath, Python

When I worked with the implementation of comments on the site for Django, I was surprised to find that Django does not provide any modules for implementation comments. Rather it gave him before, it was a unit django.contrib.comments, but in version 1.7 it was announced as deprecated and offered either to cut yourself, or you can use something like Disqus. Well, it sort of code also supports syntax highlighting, but ... in the articles one light, the other in the comments - it will be ugly.

Therefore I decided to write my own comments on the site.

To implement the necessary comments:

  • Add a new model, call it Comment ;
  • Add an idea that will handle the addition of a comment;
  • Add a form to add a comment;
  • Use Materialized Path to organize tree structure;
Sept. 16, 2016, 5:56 p.m.


Ubuntu, Gunicorn, Django, PostgreSQL, Nginx

Once access to the server with Ubuntu 16.04 was set in a previous article, it is time to expand on it everything necessary for operation of the site, namely:

  • Django - framework for developing web-applications in Python;
  • PostgreSQL - SQL database;
  • Gunicorn - WSGI HTTP Python server for UNIX systems;
  • Ngnix - HTTP-server and a reverse proxy server, mail proxy server and TCP / UDP general purpose proxy;
  • Supervisor - This process manager, which greatly simplifies the management of long-running programs, such as sites that you want to automatically restart after a fall.
Last comments
Feb. 21, 2019, 12:51 p.m.
Евгений Легоцкой

Иногда CMake приходится перезапускать начисто, не обновляет кэш
Feb. 21, 2019, 12:29 p.m.

Я указал данные строки, т.к. без них у меня вылетала следующая ошибка: By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configurat...
Feb. 21, 2019, 12:08 p.m.

Вот атк выглядит мой проектник, посмотрите его. cmake_minimum_required(VERSION 3.6)project(projecttimer)set(CMAKE_CXX_STANDARD 11)set(CMAKE_AUTOMOC ON)set(CMAKE_AUTORCC ON)find_packa...
Feb. 21, 2019, 12:04 p.m.

Смотрите, если вы используете глобально для проекта -DCMAKE_PREFIX_PATH= то вам не надо уже указывать вот эти строкиset(Qt5Core_DIR "C:/Qt/5.12.1/mingw73_64/lib/cmake/Qt5Core")set(Qt5Gui_DIR...
Feb. 21, 2019, 11:54 a.m.

Даже не запускается. main.cpp у меня точно такой же, как в статье. CMakeLists.txt пришлось немного подправить (прикрепил ниже), т.к. не находились некоторые файлы. cmake_minimum_requi...
Now discuss on the forum
Feb. 21, 2019, 8:58 a.m.
Евгений Легоцкой

Ну у меня координаты передавались в зависимости от положения курсора мыши, а в вам по сути нужно будет аналогичным способом посылать даннные из полей ввода. Так что здесь скорее интерфес...
Feb. 20, 2019, 9:55 p.m.
Евгений Легоцкой

Не до конца понимаю сути вопроса, наверное, нужно увидеть программный код и попытку его применения, но к методам базового класса можно обращаться в наследованном классе через вызов по имени ба...
Feb. 20, 2019, 3:06 p.m.
Maciej Urmański

Yes, ok I have solution! Thank you for directing me about annotate.:) Solution is: users_in = User.objects.filter(joined_users__goal=goal, joined_users__joined=True)
Feb. 20, 2019, 2:40 p.m.
Евгений Легоцкой

Думаю, что ещё можно переопределить mouseReleaseEvent(QMouseEvent* event) у QTableView, который содержит модель и немного поиграться с индексом. Если это индекс, который соответству...
Feb. 20, 2019, 10:34 a.m.
Евгений Легоцкой

Да, так тоже можно. Единственный момент в том, что lupdate не всегда понимает, к какому контексту это дело относится, и может запихать в левый контекст. В небольшом проекте это не критич...
Join us in social networks

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