{"id":224011,"date":"2014-06-03T00:06:02","date_gmt":"2014-06-02T20:06:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=224011"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=224011","title":{"rendered":"<span class=\"post_title\">Django tips &#038; tricks<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/868\/4b1\/62f\/8684b162fdd64cb645ea328236a80bb9.png\" align=\"right\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e!<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Django, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c. \u041a\u0430\u043a \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u043e\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u044f Django!..<br \/>  \u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u0432\u0435\u0442\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441 \u0434\u043e\u043b\u0435\u0439 \u043a\u0440\u0438\u0442\u0438\u0446\u0438\u0437\u043c\u0430. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \/ \u043b\u0443\u0447\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u0435 \u0441\u0432\u043e\u0438 \u00ab\u0444\u0438\u0448\u043a\u0438\u00bb \u0434\u043b\u044f django, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0451\u043c \u0438\u0437\u0434\u0430\u043b\u0435\u043a\u0430, \u0430 \u0443\u0436 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/998\/b99\/20d\/998b9920d41aa31697dc2f7586058014.png\" alt=\"venv\" align=\"right\"\/>  <\/p>\n<h4>\u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <a href=\"http:\/\/virtualenv.readthedocs.org\/\">virtualenv<\/a> \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 \u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 virtualenv, \u0442\u043e \u043e\u0442\u0432\u0435\u0442\u044c\u0442\u0435, \u043d\u0443\u0436\u0435\u043d \u043b\u0438 \u0432\u0430\u043c &#8212;no-site-packages. \u042d\u0442\u043e\u0442 \u0444\u043b\u0430\u0433 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u043e\u043c \u0444\u043b\u0430\u0433\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u00ab\u0432\u043d\u0443\u0442\u0440\u0438\u00bb \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u0443\u0432\u0438\u0434\u044f\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u00ab\u0441\u043d\u0430\u0440\u0443\u0436\u0438\u00bb. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u0432\u0430\u0448\u0438\u043c \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u043c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0430\u043a\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, python2-django, \u0442\u043e \u00ab\u0432\u043d\u0443\u0442\u0440\u0438\u00bb \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c pip install django.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u0447\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b?<\/b><\/p>\n<div class=\"spoiler_text\">\u042f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u044d\u0442\u0438\u043c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u043d\u0430 xapian. Xapian \u0438\u0434\u0451\u0442 \u0432 \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0435 xapian-core (\u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 C++) \u0438 xapian-bindings (\u043e\u0431\u0432\u044f\u0437\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u042f\u041f, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 python). \u041b\u043e\u0433\u0438\u0447\u043d\u043e \u0438\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u2014 \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u0434\u0432\u0438\u0436\u043e\u043a, \u0442\u043e \u0438 \u043e\u0431\u0432\u044f\u0437\u043a\u0438 \u043d\u0430\u0434\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u0430\u0432\u0438\u0442\u044c xapian-core \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u043c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c, \u0430 \u043e\u0431\u0432\u044f\u0437\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 pip \u043d\u0435 \u0443\u0441\u0442\u0440\u0430\u0432\u0438\u0432\u0430\u0435\u0442 (\u043a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0438\u0445 \u043d\u0435\u0442 \u0432 pip). \u0412\u044b\u0445\u043e\u0434\u0430 2:  <\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043c\u043e\u0439\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 virtualenv: .\/configure &#8212;prefix=\/path\/to\/virtualenv &#038;&#038; <a href=\"http:\/\/habrahabr.ru\/post\/130868\/\">make &#038;&#038; make install<\/a><\/li>\n<li>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0432\u0438\u0434\u0438\u043c\u044b\u043c\u0438 \u0438\u0437\u0432\u043d\u0435 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u043c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430, \u0447\u0442\u043e \u044f \u0438 \u0432\u044b\u0431\u0440\u0430\u043b<\/li>\n<\/ol>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c \u043f\u0438\u0442\u043e\u043d\u0435, \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 pip \u0432 virtualenv. \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044c \u2014 \u044d\u0442\u043e \u0441\u043c\u0435\u0441\u044c, \u0441\u043a\u0430\u0436\u0435\u043c, c++ \u0438 \u043f\u0438\u0442\u043e\u043d\u0430 \u2014 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0433\u0438\u044f.  <\/div>\n<\/div>\n<p>  \u0412\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c \/ \u043d\u0435\u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u0437 virtualenv \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u043c \/ \u043d\u0430\u043b\u0438\u0447\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 [virtualenv]\/lib\/python*.*\/no-global-site-packages.txt. \u0412\u043e\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0441\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u0440\u043e \u00ab\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u00bb virtualenv: <a href=\"http:\/\/pythonrants.wordpress.com\/2013\/12\/06\/why-i-hate-virtualenv-and-pip\/\">Why I hate virtualenv and pip<\/a> (\u0441\u0430\u0439\u0442 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442, \u0441\u043c\u043e\u0433 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/web.archive.org\/web\/20140107215813\/http:\/\/pythonrants.wordpress.com\/2013\/12\/06\/why-i-hate-virtualenv-and-pip\/\">web.archive.org<\/a>). \u0412 \u043d\u0435\u0439 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e virtualenv \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442 \u00ab\u0432\u043d\u0435\u0448\u043d\u0435\u0439\u00bb \u0441\u0440\u0435\u0434\u044b \u2014 \u0435\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e, \u0442\u043e \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u0430\u044f \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044f.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8e\/d89\/574\/f8ed89574482145ec2cea2b575753af2.png\" align=\"right\"\/>  <\/p>\n<h4>ipython<\/h4>\n<p>  Pip install <a href=\"http:\/\/ipython.org\/\">ipython<\/a> \u0437\u0430\u043c\u0435\u043d\u0438\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0439 \u0448\u0435\u043b\u043b \u043d\u0430 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439, \u0441 \u0440\u0430\u0441\u043a\u0440\u0430\u0448\u0438\u0432\u0430\u043d\u0438\u0435\u043c, \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c, \u0438\u043d\u0442\u0440\u043e\u0441\u043f\u0435\u043a\u0446\u0438\u0435\u0439, \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u043c \u0432\u0432\u043e\u0434\u043e\u043c, \u043a\u043e\u043f\u0438\u043f\u0435\u0439\u0441\u0442\u043e\u043c \u0438 \u0442.\u0434. Django \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0446\u0435\u043f\u043b\u044f\u0435\u0442 ipython, \u0435\u0441\u043b\u0438 \u043e\u043d \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d.<br \/>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 .\/manage.py shell, \u043d\u043e \u0438 \u0432 \u0434\u0435\u0431\u0430\u0433\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e import <b>i<\/b>pdb; <b>i<\/b>pdb.set_trace().<\/p>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h4>\n<p>  Django \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438. \u041d\u043e \u0438 \u0441\u0430\u043c\u0438\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c.<\/p>\n<h5>\u041a\u0430\u043a \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430\u0437\u043e\u0432\u0451\u0448\u044c, \u0442\u0430\u043a \u0438 \u0431\u0443\u0434\u0435\u0448\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/h5>\n<p>  \u041d\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435 \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 project (django-admin.py startproject project) \u2014 \u043d\u0443 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c, \u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0420\u0430\u043d\u044c\u0448\u0435 \u044f \u043d\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043e\u043c\u0435\u043d\u0443, \u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0443\u0442\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u2014 \u0442\u043e from supersite import utils, \u0442\u043e from newsite import utils. \u042d\u0442\u043e \u043f\u0443\u0442\u0430\u0435\u0442 \u0438 \u043e\u0442\u0432\u043b\u0435\u043a\u0430\u0435\u0442. \u0415\u0441\u043b\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043e\u0432\u0435\u0442 \u2014 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0439\u0442\u0435 (\u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0439\u0442\u0435) \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0432\u0441\u0435\u0445 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u0433\u043e \u0435\u0451 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0439\u0442\u0435\u0441\u044c.<\/p>\n<p>  \u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">--site.ru   |--static   |--media   |--project (\u043f\u0430\u043f\u043a\u0430 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c)      |--manage.py      |--project (\u043f\u0430\u043f\u043a\u0430 \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c)      |  |--settings.py      |  |--urls.py      |  |-- ...      |--app1      |--app2      |--... <\/code><\/pre>\n<h5>\u041a\u0443\u0434\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c html-\u0448\u0430\u0431\u043b\u043e\u043d\u044b<\/h5>\n<p>  \u041d\u0438\u043a\u043e\u0433\u0434\u0430, <b>\u043d\u0438\u043a\u043e\u0433\u0434\u0430<\/b> \u043d\u0435 \u043a\u0438\u0434\u0430\u0439\u0442\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b (.html) \u0432 \u043f\u0430\u043f\u043a\u0443 templates \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412\u0441\u0435\u0433\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c, \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u043c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<br \/>  \u0412\u043e\u0442 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e, \u0442.\u043a. \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 {% include &#8216;main.html&#8217; %}:  <\/p>\n<pre><code>\/gallery\/templates\/main.html \/reviews\/templates\/main.html <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u044d\u0442\u043e \u2014 \u0445\u043e\u0440\u043e\u0448\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c {% include &#8216;reviews\/main.html&#8217; %}:  <\/p>\n<pre><code>\/gallery\/templates\/gallery\/main.html \/reviews\/templates\/reviews\/main.html <\/code><\/pre>\n<h5>{% include %}<\/h5>\n<p>  \u041a \u0441\u043b\u043e\u0432\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 {% include &#8216;some_template.html&#8217; %}, \u0442\u043e \u0432\u0435\u043b\u0438\u043a\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u041f\u043e\u0447\u0435\u043c\u0443?<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">def view(request):     return render(         request,         'master.html',         {'var': 'Some text'}     } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;!-- master.html --&gt; Value of variable var: {{ var }}. {% include 'slave.html' %}  &lt;!-- slave.html --&gt; Again, value of variable var: {{ var }}. <\/code><\/pre>\n<p>  1) KISS \u0435\u0434\u0435\u0442 \u043b\u0435\u0441\u043e\u043c. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043a\u043e\u0434 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0430\u0437\u0431\u0438\u0442 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u2014 master.html \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u0439 slave.html, \u0438 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 html-\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f var \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u0448\u0430\u0431\u043b\u043e\u043d slave.html \u043d\u0435\u044f\u0432\u043d\u043e \u2014 var \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0441\u044f \u0432 master.html, \u0430 slave.html \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u0446\u0435\u043f\u043b\u044f\u0435\u0442\u00bb \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 master&#8217;\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u0432\u043d\u0443\u0442\u0440\u0438 {% include %} \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u041c\u044b \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u0438\u043d\u0430\u0447\u0435 \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0435 \u0442\u043e.<br \/>  2) \u041f\u043e \u043c\u043e\u0438\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f\u043c, {% include %} \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0432 \u043f\u043b\u0430\u043d\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430. \u041b\u0443\u0447\u0448\u0435 \u0435\u0433\u043e \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c.<\/p>\n<p>  \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 inclusion tags (\u043e \u043d\u0438\u0445 \u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0438\u0436\u0435). \u041d\u043e \u043f\u0440\u043e\u0449\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0438\u0442\u0435 \u0432\u0441\u0451 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435:  <\/p>\n<pre><code class=\"html\">&lt;!-- master.html --&gt; Value of variable var: {{ var }}. Again, value of variable var: {{ var }}. <\/code><\/pre>\n<h5>settings.py<\/h5>\n<p>  \u0412\u044b \u0436\u0435 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442\u0435 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 settings.py \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u0438 \u0434\u0435\u043f\u043b\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445, \u0434\u0430?<br \/>  \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 local_settings.py \u0438 deployment_settings.py, \u043a\u0443\u0434\u0430 \u0441\u043a\u0438\u043d\u044c\u0442\u0435 \u0432\u0441\u0451, \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432 local_settings.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">DEBUG = True  DOMAIN = '127.0.0.1:8000' ALLOWED_HOSTS = ['127.0.0.1', DOMAIN]  SERVER_EMAIL = 'mail@test.ru' EMAIL_HOST = 'localhost' EMAIL_PORT = 1025 EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' EMAIL_USE_TLS = False EMAIL_SUBJECT_PREFIX = '[' + DOMAIN + '] '  DEFAULT_FROM_EMAIL = 'mail@test.ru'  DATABASES = {     'default': {         'ENGINE': 'django.db.backends.postgresql_psycopg2',         'NAME': 'test',         'USER': 'test',         'PASSWORD': 'test',         'HOST': 'localhost',         'PORT': '',         'ATOMIC_REQUESTS': True,     } }  CACHES = {     'default': {         'BACKEND': 'django.core.cache.backends.dummy.DummyCache',     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 settings.py \u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435:  <\/p>\n<pre><code class=\"python\"># Load local settings if available try:     from local_settings import * except ImportError:     from deployment_settings import * <\/code><\/pre>\n<p>  \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0430 \u0434\u0435\u043f\u043b\u043e\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c local_settings.py. \u0427\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0435 \u043c\u0435\u0448\u0430\u043b\u0441\u044f, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 .gitignore.<\/p>\n<h5>\u041a\u043e\u0440\u0435\u043d\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h5>\n<p>  \u0417\u0430\u0434\u0430\u0439\u0442\u0435 \u043a\u043e\u0440\u0435\u043d\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 settings.py \u2014 \u044d\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u0436\u0438\u0437\u043d\u044c \u043f\u043e\u0442\u043e\u043c:  <\/p>\n<pre><code class=\"python\">from os import path BASE = path.dirname(path.dirname(path.dirname(path.abspath(__file__)))) MEDIA_ROOT = BASE + '\/media\/' STATIC_ROOT = BASE + '\/static\/' <\/code><\/pre>\n<h4>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b (context_processors.py), {% include %} \u0438 inclusion tags<\/h4>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <b>\u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0430\u0439\u0442\u0430<\/b> \u2014 \u0432\u0435\u0434\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438. \u041b\u0438\u0447\u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0438\u0445 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u2014 \u044d\u0442\u043e\u0442 \u043d\u043e\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f, \u0438 \u043d\u0435 \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b. \u0415\u0449\u0451 \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 \u043c\u0435\u043d\u044e \u0441\u0430\u0439\u0442\u0430. \u042f \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435, \u0438 \u0435\u0441\u043b\u0438 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u0432 \u043c\u0435\u043d\u044e \u2014 \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044e \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440, \u0438 \u043e\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0432\u0435\u0437\u0434\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u0432\u0430\u0441 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430, \u0442.\u0435. \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0435. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0441\u043e\u0437\u0434\u0430\u0442\u044c news\/context_processors.py, \u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e news \u0441 \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u043c\u0438, \u0430 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 {% include &#8216;news\/news_widget.html&#8217; %}, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 {% load news_widget %} {% news_widget news %}\u2026<\/p>\n<p>  \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u0437\u0430\u043c\u0443\u0441\u043e\u0440\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442, \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0430. \u0412\u044b\u0445\u043e\u0434 \u0435\u0441\u0442\u044c \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <a href=\"https:\/\/docs.djangoproject.com\/en\/1.6\/howto\/custom-template-tags\/#howto-custom-template-tags-inclusion-tags\">inclusion tag<\/a>. \u0412\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u0442\u0435 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 {% news %}, \u0430 \u0443\u0436\u0435 \u044d\u0442\u043e\u0442 templatetag \u0438\u0449\u0435\u0442 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439. \u0418 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u2014 \u0442.\u0435. \u043f\u0438\u0448\u0435\u0442\u0435 {% news %} \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/871\/644\/51e\/87164451efd98e7a5c0e7d183f28ef55.jpg\" align=\"right\"\/>  <\/p>\n<h4>\u0411\u0430\u0442\u0430\u0440\u0435\u0439\u043a\u0438<\/h4>\n<p>  <\/p>\n<h5>django-debug-toolbar-template-timings<\/h5>\n<p>  \u0412\u0441\u0435 \u0435\u0433\u043e \u0437\u043d\u0430\u044e\u0442 \u0438, \u043d\u0430\u0432\u0435\u0440\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442. \u041d\u043e \u0435\u0441\u0442\u044c <a href=\"https:\/\/pypi.python.org\/pypi\/django-debug-toolbar-template-timings\/0.6.1\">django-debug-toolbar-template-timings<\/a> \u2014 \u043f\u043b\u0430\u0433\u0438\u043d \u043a debug toolbar, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u0440\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0410 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u044b django \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u00ab\u0434\u043e\u0440\u043e\u0433\u0438\u0435\u00bb (\u0440\u0435\u043d\u0434\u0435\u0440\u044f\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u043e), \u0442\u043e \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0441\u0430\u0439\u0442\u0430 \u044d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d \u2014 \u0442\u043e \u0447\u0442\u043e \u0434\u043e\u043a\u0442\u043e\u0440 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b.<\/p>\n<h5>adv_cache_tag<\/h5>\n<p>  <a href=\"https:\/\/github.com\/twidi\/django-adv-cache-tag\">django-adv-cache-tag<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445 \u2014 \u0432\u0435\u0440\u0441\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u044c, \u0441\u0436\u0430\u0442\u0438\u0435, \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0435 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041f\u0440\u043e\u0441\u0442\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u0435:  <\/p>\n<pre><code class=\"html\">{% load adv_cache %} {% cache 0 object_cache_name object.pk obj.date_last_updated %}  &lt;!-- \u0417\u0430\u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430, \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u044d\u0448 \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 obj.date_last_updated --&gt;   {{ obj }}   {% nocache %}      {{ now }}  &lt;!-- \u0410 \u044d\u0442\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c --&gt;    {% endnocache %}    {{ obj.date_last_updated }} {% endcache %} <\/code><\/pre>\n<h5>django-mail-templated<\/h5>\n<p>  \u0428\u0430\u0431\u043b\u043e\u043d\u044b email \u043f\u0438\u0441\u0435\u043c \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0435\u0433\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 django. <a href=\"https:\/\/github.com\/artemrizhov\/django-mail-templated\">django-mail-templated<\/a><\/p>\n<h5>django-ipware<\/h5>\n<p>  <a href=\"https:\/\/github.com\/un33k\/django-ipware\">django-ipware<\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 ip \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0437\u0430 \u0432\u0430\u0441, \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b \u0436\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043e\u0442\u043a\u0443\u0434\u0430 \u0431\u0440\u0430\u0442\u044c ip \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f?<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">'HTTP_X_FORWARDED_FOR', # client, proxy1, proxy2 'HTTP_CLIENT_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'HTTP_VIA', 'REMOTE_ADDR', <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>Beautiful Soup<\/h5>\n<p>  \u041d\u0435 \u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u0432\u043e\u0439 \u043f\u0430\u0440\u0441\u0435\u0440 html. \u041d\u0435 \u043f\u0430\u0440\u0441\u0438\u0442\u0435 html \u0441\u0430\u043c\u0438. <a href=\"http:\/\/www.crummy.com\/software\/BeautifulSoup\/\">\u0412\u0441\u0451 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c.<\/a><\/p>\n<h4>Templatetags, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f<\/h4>\n<p>  <\/p>\n<h5>add_class<\/h5>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0435 \u0444\u043e\u0440\u043c\u0443 \u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e input-\u0430 \u0437\u0430\u0434\u0430\u0442\u044c \u0441\u0442\u0438\u043b\u044c, \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 placeholder, \u0442\u043e django \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u0432\u0430\u0441 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0438\u043b\u0438 \u043f\u0440\u044f\u043c\u043e \u0432 forms.py:  <\/p>\n<pre><code class=\"python\">class SomeForm(ModelForm):     class Meta:         model = SomeModel         fields = ('field1', 'field2')         widgets = {             'field1': Textarea(attrs={'rows': '2', 'class': 'field1_class'}),         } <\/code><\/pre>\n<p>  \u041c\u0435\u043d\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0440\u043e\u0431\u0438\u0442 \u043f\u0440\u0438 \u0432\u0438\u0434\u0435 html \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0435 \u0432 .html \u0444\u0430\u0439\u043b\u0430\u0445. \u042d\u0442\u043e \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 MVT \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0444\u0438\u043b\u044c\u0442\u0440:  <\/p>\n<pre><code class=\"html\">{% load add_class %} {{ form.field1|add_class:'field1_class' }} <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u043a \u0442\u0435\u0433\u0430\u043c, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 add_class.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">from django import template from django.utils.safestring import mark_safe from bs4 import BeautifulSoup  register = template.Library() @register.filter def add_class(html, css_class):     soup = BeautifulSoup(unicode(html), 'html.parser')      for tag in soup.children:         if tag.name != 'script':             if 'class' in tag:                 tag['class'].append(css_class)             else:                 tag['class'] = [css_class]      return mark_safe(soup.renderContents()) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>is_current_page<\/h5>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435, \u0435\u0441\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u0438\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u00ab\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u00bb \u0432 \u043c\u0435\u043d\u044e, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0435\u0439\u0447\u0430\u0441 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:  <\/p>\n<pre><code class=\"python\">from django import template from django.core.urlresolvers import resolve from project.utils import parse_args  register = template.Library() @register.filter def is_current_page(request, param):     return resolve(request.path).view_name == param <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0444\u0438\u043b\u044c\u0442\u0440, \u0430 \u043d\u0435 \u0442\u044d\u0433, \u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0442\u0443\u0442 \u043e\u0434\u043d\u0430: \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0438\u0447\u0430\u0439\u0448\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0441 {% if %}. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u2014 \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0430 \u0442\u043e\u0432\u0430\u0440\u0430, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d:  <\/p>\n<pre><code class=\"html\">{% if request|is_current_page:'shop\/product' and user.is_authenticated %} <\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u0438 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f, \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u0430\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b (args \u0438\u043b\u0438 kwargs) \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b (\u0442.\u0435. \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0442\u043e\u0432\u0430\u0440\u0430\u00bb, \u0430 \u00ab\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0442\u043e\u0432\u0430\u0440\u0430 \u0441 id=36\u00bb):  <\/p>\n<pre><code class=\"html\">{% if request|is_current_page:'shop\/product,id=36' %} <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">@register.filter def is_current_page(request, param):     params = param.split(',')     name = params[0]     args, kwargs = parse_args(params[1:])     # Do not mix args and kwargs in reverse() - it is forbidden!     if args:         return request.path == reverse(name, args=args)     elif kwargs:         return request.path == reverse(name, kwargs=kwargs)     else:         return request.path == reverse(name) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/bc6\/a59\/13d\/bc6a5913dd401f48a545de54669c812e.jpg\" align=\"right\"\/>  <\/p>\n<h4>\u041c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>  <\/p>\n<h5>\u041f\u0443\u0441\u0442\u044b\u0435<\/h5>\n<p>  \u041c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c\u0438. \u0412\u043e\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"python\">class Phrase(models.Model):     pass  class PhraseRu(models.Model):     phrase = models.ForeignKey(Phrase, verbose_name='\u0444\u0440\u0430\u0437\u0430', related_name='ru')  class PhraseEn(models.Model):     phrase = models.ForeignKey(Phrase, verbose_name='\u0444\u0440\u0430\u0437\u0430', related_name='en') <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 Phrase \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0438\u043c \u0437\u0432\u0435\u043d\u043e\u043c \u043c\u0435\u0436\u0434\u0443 PhraseEn \u0438 PhraseRu, \u0445\u043e\u0442\u044f \u0441\u0430\u043c\u0430 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442. \u041f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0430\u0432\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b, \u0438 \u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0432 \u0435\u0434\u0438\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0435.<\/p>\n<h5>Generic relation mixin<\/h5>\n<p>  \u041e\u0431\u044a\u0435\u043a\u0442\u044b GenericRelation \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f QuerySet&#8217;\u043e\u043c, \u0434\u0430\u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u044b \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0434\u0438\u043d:  <\/p>\n<pre><code class=\"python\">class Token(models.Model):     content_type = models.ForeignKey(ContentType)     object_id = models.PositiveIntegerField()     content_object = generic.GenericForeignKey()  class Registration(models.Model):     tokens = generic.GenericRelation(Token) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u043e\u043a\u0435\u043d\u0443, \u043c\u044b \u043f\u0438\u0448\u0435\u043c registration.tokens.first(). \u041d\u043e \u043c\u044b-\u0442\u043e \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0442\u043e\u043a\u0435\u043d \u043e\u0434\u0438\u043d, \u0438 \u0445\u043e\u0442\u0438\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e registration.token \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0432\u0435\u0442\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d. \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 mixin:  <\/p>\n<pre><code class=\"python\">class Token(models.Model):     content_type = models.ForeignKey(ContentType)     object_id = models.PositiveIntegerField()     content_object = generic.GenericForeignKey()  class TokenMixin(object):     @property     def token(self):         content_type = ContentType.objects.get_for_model(self.__class__)         try:             return Token.objects.get(content_type__pk=content_type.pk, object_id=self.id)         except Token.DoesNotExist:             return None  class Registration(models.Model, TokenMixin):     tokens = generic.GenericRelation(Token) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c registration.token \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!<\/p>\n<h5>get_absolute_url<\/h5>\n<p>  \u0421\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c {% url &#8216;shop\/product&#8217; id=product.id %}.<br \/>  \u041b\u0443\u0447\u0448\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 get_absolute_url(), \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 {{ object.get_absolute_url }}. \u0417\u0430\u043e\u0434\u043d\u043e \u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u00ab\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442\u0435\u00bb \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435.<\/p>\n<h5>pre_save<\/h5>\n<p>  \u0412 pre_save \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043d\u0435\u0442. \u0426\u0435\u043d\u0430 \u2014 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b.  <\/p>\n<pre><code class=\"python\">@receiver(pre_save, sender=SomeModel) def process_signal(sender, instance, **kwargs):     old_model = get_object_or_None(SomeModel, pk=instance.pk)     if not old_model:         # Created         old_value = None         ...     else:         old_value = old_model.field     new_value = instance.field      if new_value != old_value:         # field changed! <\/code><\/pre>\n<h4>\u0424\u043e\u0440\u043c\u044b<\/h4>\n<p>  \u042d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0443\u0436\u0435 \u0431\u044b\u043b \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u043d\u043e \u043e\u043d \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0445\u043e\u0440\u043e\u0448, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c \u0435\u0433\u043e.  <\/p>\n<pre><code class=\"python\">form = SomeForm(request.POST or None) if form.is_valid():     # ... actions ...     return HttpResponseRedirect(...) return render(     request,     {'form': form} ) <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/224011\/\"> http:\/\/habrahabr.ru\/post\/224011\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/868\/4b1\/62f\/8684b162fdd64cb645ea328236a80bb9.png\" align=\"right\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e!<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Django, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c. \u041a\u0430\u043a \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u043e\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u044f Django!..<br \/>  \u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u0432\u0435\u0442\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441 \u0434\u043e\u043b\u0435\u0439 \u043a\u0440\u0438\u0442\u0438\u0446\u0438\u0437\u043c\u0430. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \/ \u043b\u0443\u0447\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u0435 \u0441\u0432\u043e\u0438 \u00ab\u0444\u0438\u0448\u043a\u0438\u00bb \u0434\u043b\u044f django, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0451\u043c \u0438\u0437\u0434\u0430\u043b\u0435\u043a\u0430, \u0430 \u0443\u0436 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-224011","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/224011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224011"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/224011\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}