<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 7WebPages on Medium]]></title>
        <description><![CDATA[Stories by 7WebPages on Medium]]></description>
        <link>https://medium.com/@7WebPages?source=rss-60c4504736e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-wuckyQeT5Xfixjx.jpg</url>
            <title>Stories by 7WebPages on Medium</title>
            <link>https://medium.com/@7WebPages?source=rss-60c4504736e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:24:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@7WebPages/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Most popular Django sites]]></title>
            <link>https://medium.com/@7WebPages/most-popular-django-sites-8a9fd8e686ff?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a9fd8e686ff</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Mon, 29 Aug 2016 20:49:05 GMT</pubDate>
            <atom:updated>2016-08-29T20:49:05.682Z</atom:updated>
            <content:encoded><![CDATA[<p>The first question we ask ourselves when we approach a new project: is Django really the best option here? Even if a client is sure that the answer is confirmative. To be more certain about it, we decided to do a research on that. We wrote a script that would gather all the Django sites on the Internet (yes, we do not choose easy ways:) ) and analyse the list we receive. By this time the script is still processing and the final results will come later.</p><p>So we started with 5 popular sites on Django that everyone knows and we had a proof that they are currently working on Django Framework.</p><h4>Instagram</h4><p>[[instagram-logo]]</p><p>Yes, this source of selfies and food photos was developed in Django. Why? Instagram developers claim that choosing a technology, they were guided by three principles:</p><ol><li>Keep it very simple.</li><li>Don’t re-invent the wheel.</li><li>Go with proven and solid technologies whenever you can.</li></ol><p><strong>It’s perfect for social networks:</strong></p><ul><li>Because Django allows working efficiently with a big amount of data, here it has many images, apparently.</li><li>It can help to manage a large number of users and provides easy interaction between them.</li><li>It works well with other technologies.</li></ul><p><a href="http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances">Read more</a> what Instagram developers share about their technologies.</p><h4>2. The Washington Post</h4><p>[[washington]]</p><p>Few people know that initially Django was created to develop online editions. No wonder, the most popular newspapers have Django websites. Some of them benefit from certain advantages of Django, like The New York Times, which is mostly built on pure Python and basically uses lots of other technologies. Such newspapers as The Washington Post have their site with Django backend. This is how its developers explain their choice:</p><ul><li>sites on Django handle high traffic loads;</li><li>providing efficient and fast performance;</li><li>ability to contribute to the framework so it meets one’s own specific needs (for instance, one of its first developers Adrian Holovaty (nice to come across Ukrainian surnames so often:) ) was an active contributor to Django).</li></ul><p>It also has a lot of various apps on Django, like <a href="http://projects.washingtonpost.com/congress/">US Congress Votes Database</a> or <a href="http://apps.washingtonpost.com/national/fallen/">Faces of the Fallen</a>, for instance.</p><h4>3. Disqus</h4><p>[[disqus-logo]]</p><p>Disqus also faced the problem of scalability, like Pinterest, but it continued with Django and found <a href="http://blog.disqus.com/post/62187806135/scaling-django-to-8-billion-page-views">another way out of this problem</a>. They’ve managed to achieve 8 billion page views in 2013. And even when they needed to handle 1.5 millions concurrently connected users, 45,000 new connections per second, they also <a href="http://highscalability.com/blog/2014/4/28/how-disqus-went-realtime-with-165k-messages-per-second-and-l.html">did it with Django</a>.</p><p>Again, they point out such benefits of Django:</p><ul><li>availability of ready solutions. However, they also stress that one needs to develop within “Django” philosophy to have it function well;</li><li>again, a wide community;</li><li>and thus easiness to find good specialists.</li></ul><p>They’ve also managed to benefit from Django, providing different smaller side services and after they extended on “<a href="https://www.youtube.com/watch?v=vkCuRFM3GVE">How they do it when it isn’t Django</a>”, which means how they used different technologies to make them get friends with Django. <a href="https://archive.org/details/EuroPython_2014_nbkwcdlH">They moved back to Django</a>, mainly because of its wide community and yes, due to the fact that they’ve already worked with it.</p><h4>4. Zapier</h4><p>[[zapier-logo]]</p><p>Now we’ll move from globally popular sites to rather popular ones in certain circles. For instance, Zapier gained its glory in the business world. This service helps to connect various similar services into one. For instance, one can save G-mail attachments to Dropbox or create a Trello ticket from his calendar.</p><p>An interesting fact is that you can also validate that Zapier is running on Django by just opening their <a href="https://zapier.com/admin/">admin login page</a>. It shows a default Django interface for the admin panel.</p><p>From the development perspective, it’s a really fascinating one:</p><ul><li>it connects different sources (via APIs) and enables quick collaboration between different sources of information; 141 APIs have been <a href="http://thenextweb.com/insider/2014/01/15/app-automation-service-zapier-overhauls-developer-platform-speed/">added to Zapier</a> by January 2014;</li><li>what is more, it enables performing different actions by means of the service without switching from one app to another;</li><li>it enables work with a big amount of data for thousands of users.</li></ul><p>The choice of Django was based on familiarity, according to the <a href="https://zapier.com/blog/zapier-tech-stack/">article</a> by Bryan Helmig. They just chose the technology they were acquainted with. Thus, they basically chose Python/Django before working for Zapier. It should be mentioned, Bryan states that Ruby, e.g., would not be a worse choice. However, nobody has proved his point in practice:)</p><p>By the way, Zapier also turns to ReactJS and even prepared a small <a href="https://zapier.com/engineering/react-js-tutorial-guide-gotchas/">tutorial</a> for those who also consider it a good choice. So do we.</p><h4>5. Bitbucket</h4><p>[[bitbucket]]</p><p>Bitbacket also doesn’t hide its roots, you can see Django admin panel on <a href="https://bitbucket.org/admin/">https://bitbucket.org/admin/</a></p><p><a href="https://medium.com/code.djangoproject.com/wiki/djangosuccessstorybitbucket">This article</a> shows its developer had fallen in love with Django much earlier than the development of Bitbucket started. However, this love continues till now. Which means it’s a true love and not the love of the kind “I was lazy to find something else, and you’re ok”. Why is that so?</p><ul><li>Its developers claim that it wouldn’t be for the Django’s wide community which keeps it fit and up to date.</li><li>Moreover, one doesn’t need to pay for all the apps separately, such as URL mapping. They’re also grateful for Django’s having so many ready parts for them to use, rather than developing from scratch. That’s why they had such a short turn-around time.</li></ul><p>Concerning the drawbacks of Django, they point out its problems with “Group by” (yes, we’ve been there too:) ) expressions and a lack of flexibility in ORM usage.</p><h4>Django Myths</h4><p>At first glance, it may seem that much more sites were successfully developed on Django. They present head rushing figures with a number of users so that everybody is rushing to use Django only and nothing else can be efficient when it comes to complicated functionality.</p><p>Let’s slow down and gaze more attentively at these sites. At last I’ll feel a little how it’s to be a myth buster.</p><p><strong>Pinterest is not the best example of Django usage</strong> (I can hear some myths bumping into the wall). Its developers even claim that if they started the development now, they would have started from Flask again. And yes, they have. Since 2012 Pinterest has been running on Flask (according to <a href="https://qph.is.quoracdn.net/main-qimg-98f94f2af1d068d6addd415011959a44?convert_to_webp=true">its developers’ answers</a>). Its developers <a href="https://www.quora.com/Would-Pinterest-consider-Flask-in-place-of-Django-if-it-were-starting-today">claim</a> it to be much simpler than Django, and in their case made the platform more lightweight.</p><p>Another myth turned out to be even crueller to me. I’ve googled looking hard for the information about **how the New York Times site **was written on Django. I still wonder how this myth spread on the Internet as I failed to find any information about Django usage (Pinterest was at least first developed on it). This powerful site uses a lot of different technologies, actively Python, but it must be mentioned, also Ruby on Rails. It does have some parts on Django. Its developers, for instance, obviously adore <strong>Geodjango</strong>. They’ve even developed <a href="http://open.blogs.nytimes.com/2013/11/01/building-the-other-races/?_r=0">The Other Races</a>, a special app that provides the election data from different states. In general, I can’t but get amused with the work of its developers when I review this site. They are not just a powerful magazine site, but also a learning tool, providing a lot of sideapps. However, this is a proof of Python’s coolness, not Django’s. By the way, they do have an informative <a href="http://open.blogs.nytimes.com/?_r=0">blog</a>: I guess it will be useful for the developers who want to be confident when they choose this or that development tool for their projects.</p><h4>Read more:</h4><p>“Code.” DjangoSuccessStoryBitbucket — Django. Web. 15 Dec. 2015.</p><p>“Code — Open Blog — The New York Times.” Code — Open Blog — The New York Times. Web. 15 Dec. 2015. <a href="http://open.blogs.nytimes.com/?_r=0">http://open.blogs.nytimes.com/?_r=0</a>.</p><p>“How Disqus Went Realtime with 165K Messages Per Second and Less than .2 Seconds Latency — High Scalability -.” How Disqus Went Realtime with 165K Messages Per Second and Less than .2 Seconds Latency — High Scalability -. Web. 15 Dec. 2015.</p><p>“How Zapier Uses Mailgun to Send Emails.” Mailgun Blog. 18 June 2015. Web. 15 Dec. 2015. <a href="http://blog.mailgun.com/how-zapier-uses-mailgun-to-send-emails/">http://blog.mailgun.com/how-zapier-uses-mailgun-to-send-emails/</a>.</p><p>“Learn How Disqus Does ‘It’ When ‘It’ Isn’t Django.” YouTube. YouTube. Web. 15 Dec. 2015. “News &amp; Events.” Django in Use at Washingtonpost.com. Web. 15 Dec. 2015.</p><p>“Scaling Django to 8 Billion Page Views.” Scaling Django to 8 Billion Page Views. Web. 15 Dec. 2015.</p><p>“Scaling Pinterest — From 0 to 10s of Billions of Page Views a Month in Two Years — High Scalability -.” Scaling Pinterest — From 0 to 10s of Billions of Page Views a Month in Two Years — High Scalability -. Web. 15 Dec. 2015.</p><p>“The Zapier Tech Stack.” The Zapier Blog. Web. 15 Dec. 2015. <a href="https://zapier.com/blog/zapier-tech-stack/">https://zapier.com/blog/zapier-tech-stack/</a>.</p><p>“Websites Using Django | Five Q | Blog | Five Q.” Websites Using Django | Five Q | Blog | Five Q. Web. 15 Dec. 2015.</p><p>“[EuroPython 2014] Adam — How Disqus Is Using Django as the Basis of Our Service Oriented Architecture : Free Download &amp; Streaming : Internet Archive.” Internet Archive. Web. 15 Dec. 2015.</p><p>“What Is the Technology Stack behind Pinterest?” — Quora. Web. 15 Dec. 2015. <a href="https://www.quora.com/What-is-the-technology-stack-behind-Pinterest-1">https://www.quora.com/What-is-the-technology-stack-behind-Pinterest-1</a>. “Would Pinterest Consider Flask in Place of Django If It Were Starting Today?” — Quora. Web. 15 Dec. 2015.</p><p>“Zapier Overhauls Developer Platform.” TNW Network All Stories RSS. 15 Jan. 2014. Web. 17 Dec. 2015. <a href="http://thenextweb.com/insider/2014/01/15/app-automation-service-zapier-overhauls-developer-platform-speed/">http://thenextweb.com/insider/2014/01/15/app-automation-service-zapier-overhauls-developer-platform-speed/</a>.</p><p>“What Powers Instagram: Hundreds of Instances, Dozens of Technologies.” — Instagram Engineering. Web. 15 Dec. 2015.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a9fd8e686ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FAQ]]></title>
            <link>https://medium.com/@7WebPages/faq-acbb6349d5a2?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/acbb6349d5a2</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Wed, 17 Aug 2016 15:05:33 GMT</pubDate>
            <atom:updated>2016-08-17T15:05:33.612Z</atom:updated>
            <content:encoded><![CDATA[<p>Before getting to the questions about the project start and its maintenance, you can review our <a href="https://7webpages.com/blog/outsourcing-to-ukraine/">article</a> about why outsourcing to Ukraine is a good decision.</p><h4>1. How do you approach development? What needs to be prepared to start the project?</h4><p>To start a new project:</p><p>It mainly depends on what approach is more suitable for the project. If we go with Agile, we need to have -a backlog with the tasks of first priority, -a description of the project vision (kind of an idea that we’ll keep in mind all the time to meet your expectations)</p><p>If it’s a fixed price project, we need to fix the scope, thus, we need -a specification document. We can work on it together if you want. If a client side hasn’t a programming specialist, we develop them by ourselves, involving client into the discussion of the main functionality part but working out the details by ourselves. Specification document must be agreed on before the contract is signed. If you want to learn more about it, please read our article about perfect <a href="https://7webpages.com/blog/best-requirements/">requirements</a></p><p>In both cases, we need to have a contract signed. We do our best to describe the way we collaborate as thoroughly as we can, to avoid any misunderstandings and be able to concentration on the development only. Ways of communication, frequency of the reports, contact people, risk situations and many other moments. Write to us — info@7webpages.com — and we’ll give you an example of the contract.</p><p>If it’s an existing project, we need:</p><p>to transfer credentials; to investigate some time into the code investigation.</p><h4>2. How much time does it take to launch a project development?</h4><p>About a week or two. Of course, it depends on the project and your team availability. If we go with Agile, it usually takes a really small amount of time. If we need specifications to be developed, it adds time. For instance, for a two-week project we need a day to have the specs ready and, if the client is available, for him to comment on them and accept. If the project requires some discovery, we estimate this effort separately.</p><h4>3. How is the work checked/tested? How can I make sure that I’ve accepted a high-quality work?</h4><p>Our code is covered with tests. It means that at least the basic functionality of your site or app is checked as a result of Test Driven Development. If we have enough time, we add tests for minor functionality as well.</p><p>We can also provide a tester to work on your project. We have a senior tester in our team, and she checks the project first by chunks, and then does a general testing to make sure everything works. If you decide to go without a tester before you get the work to check, our Project Manager will review it, but of course, a tester will provide a much more detailed analysis.</p><h4>4. Do you guys take care of hosting setup and everything? Or we need to do it by ourselves?</h4><p>It depends whether you want it, of course:) But mostly we do it and it’s automatically included to our estimations. We also help our clients to choose the best hosting provider and tell which plan would be reasonable to subscribe for.</p><ol><li>When do I get the access to the code?</li></ol><p>If you go with Agile, you have it from the start. If you choose a fixed price, you get the code after the payment is made. We usually break the work into chunks and prefer receiving the payment in such a way as well. Thus, the risks for both sides are minimal.</p><p>Meanwhile, you can always evaluate our progress. First, we deploy the code to our development server where we test and check. You can always enter and take a look. Moreover, we are very happy if you have time to review our intermediate results and make some comments on the go. Good news: we don’t charge for hosting for the dev version.</p><h4>6. Do you usually setup https certificates and alike?</h4><p>Yes, we also help to choose one and once you buy it or choose (if it’s free), we set it up by ourselves.</p><p>Often we advise using free and reliable initiative from Mozilla letsencrypt.com</p><h4>7. Will my site be SEO optimized?</h4><p>Yes: metatags and sitemap will be organized.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acbb6349d5a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Outsourcing to Ukraine]]></title>
            <link>https://medium.com/@7WebPages/outsourcing-to-ukraine-e319b4dd98f4?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e319b4dd98f4</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Wed, 27 Jul 2016 09:56:28 GMT</pubDate>
            <atom:updated>2016-07-27T09:56:28.284Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>Ukraine is a proven Software development partner for the USA. Samsung, NetCracker, SysIQ, Wargaming and more than other 90 different global tech companies have R&amp;D centers in Ukraine. Around 45% of these companies have headquarters in the US. These companies have already checked this source of talents, so you can be confident about it. Read more {http://www.samsung.com/ua/aboutsamsung/samsungelectronics/careers/SamsungUkraineResearchCenter.html}, {https://www.netcracker.com/}, {http://astoundcommerce.com/}, {http://wargaming.com/en/careers/}</li><li>According to the rating “The Global Outsourcing 100”, 4 Ukrainian companies are in TOP-5 outsourcing companies and 3 more are the best 75 leaders. Rating was assumed according to the recommendations of clients from the USA and Europe {https://www.iaop.org/Content/19/165/4129}</li><li>Ukrainian IT market is the first country in Europe and the fourth in the world by the freelancer earnings, and it’s growing even more actively. Upwork statistics shows that the annual income on this platform is about $61m for approximately 123 thousand Ukrainians. What is more, tendency is very positive as Ukraine is in TOP-10 countries in the rate of freelance earnings growth (10–25%) {http://elance-odesk.com/online-work-report-global}</li></ul><figure><img alt="freelance earnings" src="https://cdn-images-1.medium.com/max/620/0*eubDoFTBR5jDgKz3.jpg" /></figure><ul><li>screenshot taken from {http://www.imena.ua/blog/upwork-for-ua-freelance/}</li><li>Ukraine has decent techical education system which is represented by 800 higher education institutions with 16000 annual graduates in the IT sphere. That’s why, Ukrainian developers are very good engineers and architects. {http://n-ix.com/offshore-development-center-in-ukraine-5-highlights/}</li><li>Most Ukrainian IT companies are oriented at long-term projects with technological challenges. There are about 1000 outsourcing IT companies in Ukraine, so the competition is high.</li><li>Good external conditions in Ukraine are achieved by exemption from VAT and 5% tax for IT industry {http://n-ix.com/offshore-development-center-in-ukraine-5-highlights/}</li><li>Ukrainian time zone is really close to Europe, so there will be almost no difference to work with freelancer</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e319b4dd98f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing online multiplayer game with python and asyncio [part 1]]]></title>
            <link>https://medium.com/@7WebPages/writing-online-multiplayer-game-with-python-and-asyncio-part-1-3b0e080493b1?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b0e080493b1</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Thu, 07 Jul 2016 14:00:26 GMT</pubDate>
            <atom:updated>2016-07-07T14:00:26.477Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Have you ever combined async with Python? Here I’ll tell you how to do it and show it on a </strong><a href="http://snakepit-game.com/"><strong>working example</strong></a><strong> — a popular Snake game, designed for multiple players.</strong></p><p><a href="http://snakepit-game.com/">Play game</a></p><h4>1. Introduction</h4><p>Massive multiplayer online games are undoubtedly one of the main trends of our century, in both tech and cultural domains. And while for a long time writing a server for a MMO game was associated with massive budgets and complex low-level programming techniques, things are rapidly changing in the recent years. Modern frameworks based on dynamic languages allow handling thousands of parallel user connections on moderate hardware. At the same time, HTML 5 and WebSockets standards enabled the creation of real-time graphics-based game clients that run directly in web browser, without any extensions.</p><p>Python may be not the most popular tool for creating scalable non-blocking servers, especially comparing to node.js popularity in this area. But the latest versions of Python are aimed to change this. The introduction of <a href="https://docs.python.org/3/library/asyncio.html">asyncio</a> library and a special <a href="https://docs.python.org/3/whatsnew/3.5.html#whatsnew-pep-492">async/await</a> syntax makes asynchronous code look as straightforward as regular blocking code, which now makes Python a worthy choice for asynchronous programming. So I will try to utilize these new features to demonstrate a way to create an online multiplayer game.</p><h4>2. Getting asynchronous</h4><p>A game server should handle a maximum possible number of parallel users’ connections and process them all in real time. And a typical solution — creating threads, doesn’t solve a problem in this case. Running thousands of threads requires CPU to switch between them all the time (it is called <em>context switching</em>), which creates big overhead, making it very ineffective. Even worse with processes, because, in addition, they do occupy too much memory. In Python there is even one more problem — regular Python interpreter (CPython) is not designed to be multithreaded, it aims to achieve maximum performance for single-threaded apps instead. That’s why it uses GIL (<em>global interpreter lock</em>), a mechanism which doesn’t allow multiple threads to run Python code at the same time, to prevent uncontrolled usage of the same shared objects. Normally the interpreter switches to another thread when currently running thread is waiting for something, usually a response from I/O (like a response from web server for example). This allows having non-blocking I/O operations in your app, because every operation blocks only one thread instead of blocking the whole server. However, it also makes general multithreading idea nearly useless, because it doesn’t allow you to execute python code in parallel, even on multi-core CPU. While at the same time it is completely possible to have non-blocking I/O in one single thread, thus eliminating the need of heavy context-switching.</p><p>Actually, a single-threaded non-blocking I/O is a thing you can do in pure python. All you need is a standard <a href="https://docs.python.org/2/library/select.html">select</a> module which allows you to write an event loop waiting for I/O from non-blocking sockets. However, this approach requires you to define all the app logic in one place, and soon your app becomes a very complex state-machine. There are frameworks that simplify this task, most popular are <a href="http://www.tornadoweb.org/">tornado</a> and <a href="http://twistedmatrix.com/">twisted</a>. They are utilized to implement complex protocols using callback methods (and this is similar to node.js). The framework runs its own event loop invoking your callbacks on the defined events. And while this may be a way to go for some, it still requires programming in callback style, what makes your code fragmented. Compare this to just writing synchronous code and running multiple copies concurrently, like we would do with normal threads. Why wouldn’t this be possible in one thread?</p><p>And this is where the concept of <em>microthreads</em> come in. The idea is to have concurrently running tasks in one thread. When you call a blocking function in one task, behind the scenes it calls a “manager” (or “scheduler”) that runs an event loop. And when there is some event ready to process, a manager passes execution to a task waiting for it. That task will also run until it reaches a blocking call, and then it will return execution to a manager again.</p><blockquote><em>Microthreads</em> are also called <em>lightweight threads</em> or <em>green threads</em> (a term which came from Java world). Tasks which are running concurrently in pseudo-threads are called <em>tasklets</em>, <em>greenlets</em> or <em>coroutines</em>.</blockquote><p>One of the first implementations of <em>microthreads</em> in Python was <a href="http://www.stackless.com/">Stackless Python</a>. It got famous because it is used in a very successful online game <a href="http://www.eveonline.com/">EVE online</a>. This MMO game boasts about a persistent universe, where thousands of players are involved in different activities, all happening in the real time. <em>Stackless</em> is a standalone Python interpreter which replaces standard function calling stack and controls the flow directly to allow minimum possible context-switching expenses. Though very effective, this solution remained less popular than “soft” libraries that work with a standard interpreter. Packages like <a href="http://eventlet.net/">eventlet</a> and <a href="http://www.gevent.org/">gevent</a> come with patching of a standard I/O library in the way that I/O function pass execution to their internal event loop. This allows turning normal blocking code into non-blocking in a very simple way. The downside of this approach is that it is not obvious from the code, which calls are non-blocking. A newer version of Python introduced native <em>coroutines</em> as an advanced form of generators. Later in Python 3.4 they included <a href="https://docs.python.org/3/library/asyncio.html">asyncio</a> library which relies on native coroutines to provide single-thread concurrency. But only in python 3.5 coroutines became an integral part of python language, described with the new keywords async and await. Here is a simple example, which illustrates using asyncio to run concurrent tasks:</p><pre>import asyncio<br><br>async def my_task(seconds):<br>    print(&quot;start sleeping for {} seconds&quot;.format(seconds))<br>    await asyncio.sleep(seconds)<br>    print(&quot;end sleeping for {} seconds&quot;.format(seconds))<br><br>all_tasks = asyncio.gather(my_task(1), my_task(2))<br>loop = asyncio.get_event_loop()<br>loop.run_until_complete(all_tasks)<br>loop.close()</pre><p>We launch two tasks, one sleeps for 1 second, the other — for 2 seconds. The output is:</p><pre>start sleeping for 1 seconds<br>start sleeping for 2 seconds<br>end sleeping for 1 seconds<br>end sleeping for 2 seconds</pre><p>As you can see, coroutines do not block each other — the second task starts before the first is finished. This is happening because asyncio.sleep is a coroutine which returns execution to a scheduler until the time will pass. In the next section, we will use coroutine-based tasks to create a game loop.</p><p>Read more:</p><p><a href="https://7webpages.com/blog/writing-online-multiplayer-game-with-python-and-asyncio-writing-game-loop/">Part 2. Writing Game Loop</a> <a href="https://7webpages.com/blog/writing-online-multiplayer-game-with-python-and-asyncio-part-3/">Part 3. Making a complete game</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b0e080493b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling AWS instances backup system with python]]></title>
            <link>https://medium.com/@7WebPages/handling-aws-instances-backup-system-with-python-144d7ad708a6?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/144d7ad708a6</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Wed, 16 Mar 2016 16:26:59 GMT</pubDate>
            <atom:updated>2016-03-16T16:26:59.535Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>How to setup</strong>** AWS backup with python.**</h3><h4><strong>What this article is about</strong></h4><p>Amazon EC2 is one of the most popular cloud platforms. There are two Amazon-based options to make backups:</p><ol><li>You can make a copy of your whole server data with all system files and packages you’ve already installed. More time-consuming.</li><li>Configure your system to store all important data in separate volume (<a href="https://aws.amazon.com/ebs/">Amazon Elastic Block Store</a> volume). Next, you make backups of that volume only. Less time-consuming.</li></ol><p>In this article you will see how to implement authomatic EC2 backup (both options) with python.</p><p>Before we start, you’d better <a href="http://docs.pythonboto.org/en/latest/">go and read about boto</a>, as we’re going to use it heavily.</p><h3><strong>Possible approaches on AWS for backups</strong></h3><h4><strong>WHOLE IMAGE (AMI) BACKUP</strong></h4><ol><li><a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-instance_linux.html">Create an Amazon instance</a>, install all required packages and set up applications you need.</li><li><a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html">Attach</a> separate volume to your instance and mount it to /mnt/data.</li><li>Configure this applications in such a way that all your precious data will be saved somewhere in the mounted volume.</li><li>Check everything is working fine, stop your applications and delete all garbadge files that were probably generated during testing.</li><li><a href="http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CreateImage.html">Create an image</a> of your instance.</li></ol><p>Now, you can generate new instances from this image. They are restored from snapshot, so no need of additional configuration or setup. This is the main reason to make a whole image backup.</p><h4><strong>Restoration process</strong></h4><p>So you already have an image of your Amazon instance and you want to test it. With python code below you can make a copy of your backup instance. It will also create and mount a volume for your data.</p><p>You can also do it manually: just launch image for particular instance in AMI’s tab in AWS console (FIXME: тут надо картинка)</p><p><a href="https://github.com/maximzxc/aws_samples/blob/master/restore_instance.py">Link to the code</a></p><p>Some explanations for that code:</p><p>Create config file first. You will store all required settings for scripts there. <a href="https://github.com/maximzxc/aws_samples/blob/master/config.py">Example is here</a>.</p><p>Now let’s comment some code.</p><p>We put loggers to all important code parts to make debugging simpler.</p><pre>logger = logging.getLogger(&#39;maas&#39;)</pre><p>You may notice that some of our code is wrapped in try/except blocks; it’s important to have because when we try to connect to server something bad (e.g., loss of internet connection) may happen. So we try to repeat the request a couple of times. In the worst case, we will get info about error in log files.</p><p>When instance is started, we can automatically execute some pre-saved commands. You can set up commands to execute on startup manually: just go to the instances tab, select desired instance and change user data. All commands from this field will be automatically executed every time server starts.</p><p>To automate this — edit USER_SCRIPT_TEMPLATE variable:</p><ol><li>mount volume connected to your instance</li><li>you can execute some commands you need.</li></ol><p>You can place all your commands after ‘mount -a’ command. ATTENTION: debugging here is really painful, so you should be very attentive when you write such scripts..</p><pre>USER_SCRIPT_TEMPLATE = &quot;&quot;&quot;#!/bin/bash -ex<br>exec &gt; &gt;(tee /var/log/user-data.log|logger -t user-data -s 2&gt;/dev/console) 2&gt;&amp;1<br><br>## setup the ebs volume for data.<br>avail_blk=`lsblk -n -oNAME,MOUNTPOINT | grep -v &#39;/$&#39; | grep -v &#39;xvda&#39; | awk -F&#39; &#39;   &#39;{{print $1}}&#39;`<br>if [ -z &quot;$avail_blk&quot; ]; then<br>    echo &quot;Don&#39;t have a mounted data blk device.&quot;<br>    exit -1<br>fi<br><br>update_needed=`file -s /dev/$avail_blk | awk -F&#39;:&#39; &#39;{{print $2}}&#39;`<br>setup_fs=`echo &quot;$update_needed&quot; | egrep -e &#39;^[[:space:]]+data$&#39; |wc -l`<br><br>if [ $setup_fs -eq 1 ]; then<br>    echo &quot;Setting up a file system for /dev/$avail_blk&quot;<br>    mkfs -t ext4 /dev/$avail_blk<br>fi<br>cp /etc/fstab /etc/fstab.orig<br>echo &quot;/dev/$avail_blk /mnt/data ext4 defaults,nofail,nobootwait 0 2&quot; &gt;&gt; /etc/fstab<br>mount -a<br>&quot;&quot;&quot;</pre><p>Probably your application needs permission on mounted directory, so you can set them. Also, you should create all folders your application will use.</p><pre>USER_SCRIPT_TEMPLATE += &quot;&quot;&quot;<br>chown -R www-data:www-data /mnt/data/<br>mkdir /mnt/data/... # here you have to create all required folders for your app<br>touch /mnt/data/... # here you have to create all required files for your app<br>chown -R www-data:www-data /mnt/data/*<br>&quot;&quot;&quot;</pre><p>Also you can change some settings for your app if you want.</p><pre>USER_SCRIPT_TEMPLATE += &quot;&quot;&quot;<br># here you can change some settings files for your app<br>echo &quot;{some_variable_to_pass}&quot; &gt;&gt; # path to system file<br>&quot;&quot;&quot;</pre><p>As in the snapshot we have all our applications stopped, you should start all of them again in the script:</p><pre>USER_SCRIPT_TEMPLATE += &quot;&quot;&quot;<br># here start all your apps<br>sudo service supervisor start<br>supervisorctl start all<br>&quot;&quot;&quot;</pre><p>In the code we use conn variable to make requests to Amazon server. In code block below we try to create our instance:</p><pre>conn = boto.ec2.connect_to_region(<br>            AWS_REGION,<br>            aws_access_key_id=AWS_ACCESS_KEY_ID,<br>            aws_secret_access_key=AWS_SECRET_ACCESS_KEY<br>)<br>reservation = conn.run_instances(<br>    AWS_AMI_IMAGE_ID,<br>    instance_type=instance_type,<br>    key_name=AWS_KEY_NAME,<br>    security_group_ids=AWS_SECURITY_GROUPS,<br>    subnet_id=AWS_SBNET_ID,<br>    block_device_map=bdm,<br>    user_data=user_data,<br>)</pre><p>And then wait until it is created:</p><pre>instance = reservation.instances[0]<br>while instance.update() != &quot;running&quot;:<br>    time.sleep(5)</pre><p>And at last check if it works as expected:</p><pre>assert instance.ip_address is not None<br>assert instance.update() == &quot;running&quot;</pre><h4><strong>DATA VOLUME BACKUP</strong></h4><p>When you have volume connected to your instance, the only entity for you to make a backup is volume. You don’t need to backup the whole instance, as all changeable data is stored at volume. This will save your time and resources. Here’s how to do this:</p><h4><strong>Backup process</strong></h4><p>With the code below you can make backups of data volumes of all your instances.</p><p>You can create snapshots instance-by-instance manually in volumes tab:</p><p><a href="https://github.com/maximzxc/aws_samples/blob/master/backup_data.py">Link to the code</a></p><p>Some code explanations:</p><p><a href="https://github.com/maximzxc/aws_samples/blob/master/backup_data.py#L93">Here</a> we get list of all our Amazon instances:</p><pre>instances = conn.get_only_instances()</pre><p><a href="https://github.com/maximzxc/aws_samples/blob/master/backup_data.py#L103">Here</a> we try to get data volume id for each instance. If it exists, we create a new snapshot from it. We ignore instances without id.</p><pre>for instance in instances:<br>    data_vol_id = extract_non_root_id(<br>        instance.get_attribute(&quot;blockDeviceMapping&quot;))<br>    if data_vol_id:<br>        manage_snapshots(conn, data_vol_id)</pre><p>After new snapshot is created, we delete oldest snapshots in the <a href="https://github.com/maximzxc/aws_samples/blob/master/backup_data.py#L14">delete_old_snapshots function</a>, ignoring four newest ones. We can also provide one additional snapshot we want to keep (exclude_snap).</p><pre>volume = conn.get_all_volumes([vol_id])[0]<br>snapshots = volume.snapshots()<br>snapshots_sorted = sorted(<br>    [(s, s.start_time) for s in snapshots],<br>    key=lambda k: k[1]<br>)[4:]<br>for snapshot, start_time in snapshots_sorted:<br>    if snapshot.id == exclude_snap:<br>        continue<br>    info = &quot;deleting snap {id}: {desc}&quot;.format(<br>        id=snapshot.id, desc=snapshot.description<br>    )<br>    logger.info(info)<br>    snapshot.delete()</pre><p>Run <a href="https://github.com/maximzxc/aws_samples/blob/master/backup_data.py#L79">manage_instances_snapshots</a> a couple of times from python shell. For each volume you will have up to four snapshots.</p><h4><strong>Restoration process</strong></h4><p>You can restore backups manually: just create an image from snapshot on snapshots tab:</p><p>But a script will make massive backups much easier. <a href="https://github.com/maximzxc/aws_samples/blob/master/restore_data.py">Link to the code</a></p><p>This process is very similar to instance restoration process above. The core difference here is that you have to stop your current instance.</p><p>We do it in fuction try_to_stop_ec2_instance FIXME: link. First we have to try to stop it.</p><pre>conn.stop_instances([instance_id])<br>reservations = conn.get_all_reservations([instance_id])<br>instance = reservations[0].instances[0]</pre><p>Then we wait until it is stopped:</p><pre>while instance.update() != &quot;stopped&quot;:<br>    time.sleep(5)<br>return &quot;stopped&quot;</pre><p>Then we do the same as instance restoration process above. You should create a new instance from image and then mount your backuped data volume to it. After it is mounted you can add any code that you want to execute on this instance startup, we explained it more detaily in our previous article about whole image backups, in explanation of restoration process. Again probably you should set up special right to this data. At last you should start all your apps.</p><p>To restore, you should call function <a href="https://github.com/maximzxc/aws_samples/blob/master/restore_data.py#L84">try_to_create_ec2_instance</a> with id of volume snapshot from which you want to restore data (backup id) as first argument and id of current instance as second argument (because we have to stop this instance).</p><pre>instance = try_to_create_ec2_instance(non_root_snap_id, instance_id)</pre><p>As you can see, logic here is almost the same as in the first case, so you can use analogy.</p><h3><strong>Afterword</strong></h3><p>We really hope this article helps you. But, if you’re not sure you can easily setup backups on the Amazon — we can do that for you, fast and affordable. Please, <a href="http://somewhere/">contact us</a>, we will answer any questions!</p><p>or:</p><p>we really hope this article is useful for you. But if something is not clear — we can setup backup system on Amazon, or answer any questions. Please, <a href="http://smth/">contact us</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=144d7ad708a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basecamp oAuth provider for django-allauth]]></title>
            <link>https://medium.com/@7WebPages/basecamp-oauth-provider-for-django-allauth-5df859bbbc5f?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5df859bbbc5f</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Wed, 16 Mar 2016 16:09:26 GMT</pubDate>
            <atom:updated>2016-03-16T16:09:26.582Z</atom:updated>
            <content:encoded><![CDATA[<p>Plan</p><h4><strong>INTRO</strong></h4><p>In this article you will see how to create custom provider module for a <a href="https://github.com/pennersr/django-allauth">django-allauth</a> package. I’ll do it on real example of Basecamp provider module I’ve written; it’s already accepted into the codebase of django-allauth on <a href="https://github.com/pennersr/django-allauth/pull/1077/">github</a>.</p><h4><strong>WHAT IS DJANGO-ALLAUTH?</strong></h4><p>There is always a task to integrate social networks and different platforms into our site. It enables user to login on our site using his existing account on one of the platforms. Historically there were different libraries in Django framework for that. The first good approach in my mind was a <a href="https://medium.com/%D1%81%D1%81%D1%8B%D0%BB%D0%BE%D1%87%D0%BA%D0%B0">django-social-auth</a> that was started nearly 5 years ago and actively maintained till now. I used it a lot and even wrote a Trello provider to for that. However, recently, about 2 years ago, another package started to became more and more popular. The package name is ‘django-allauth’. The major difference from django-social-auth is the fact that it includes plain email-based registration. With django-social-auth, I’ve had to use an additional package named django-registration to implement such functionality. That’s why I’ve switched to django-allauth: it takes less time for me to implement typical register/login functionality, both social and email-based.</p><h4><strong>HOW OAUTH WORKS</strong></h4><p>There is general agreement that handles the process of authorization using account from external site. It’s OAuth (Open Auth) protocol.</p><p>The general idea is following:</p><ul><li>User is on our site (www.campscore.io)</li><li>User clicks on specific link that brings him/her to the Oauth provider site where he/she is registered (www.basecamp.com)</li><li>Basecamp asks user if User allows to pass details of his/her account (email, name, photo but not the password) to <a href="http://www.campscore.io/">www.campscore.io</a></li><li>If user allowed access to his/her details — user is redirected back to <a href="http://www.campscore.io/">www.campscore.io</a></li><li>When user is redirected, Basecamp adds specific temporary key to the url. CampScore receives this key and use it to make an internal request to the Basecamp to receive the data.</li></ul><p>When we go into details there are two versions of OAauth protocols: OAuth1 and OAuth2. The have differencies that are well explained in this stackoverflow answer:<a href="http://stackoverflow.com/questions/4113934/how-is-oauth-2-different-from-oauth-1">http://stackoverflow.com/questions/4113934/how-is-oauth-2-different-from-oauth-1</a></p><p>We will work with OAuth2 version of protocol as it’s simpler and more convenient to use. I’ll took an image from stackoverflow answer to illustrate how it works in details.</p><p>This diagram has more steps that I’ve outlined before. It additionally contains: — exchange key that Basecamp returned us to the Access Token that we can use to access the data.</p><p>I have to mention also that developer must create a record on OAuth provider site in order to be able to authorize users. This record contain: name of the app that asks for permission, a name of the company that owns an app, app domain name, url to redirect user when he/she grants access, url to redirect user when he/she did not allow to provide personal information.</p><p>The place to create an app usually can be found in developer documentation for OAuth on the OAuth provider site.</p><p>For example, basecamp app can be registered here: <a href="https://integrate.37signals.com/apps/new">https://integrate.37signals.com/apps/new</a>. The interface looks like following.</p><h4><strong>STRUCTURE OF PROVIDER MODULE IN DJANGO-ALLAUTH</strong></h4><p>Django-allauth provides very handy base classes that do all the routine work. Basically adding a provider is more like configuration then coding.</p><p>Base classes you need to reuse are following:</p><ul><li>It’s base views that handle all redirects and processing responses from partner: OAuth2Adapter, OAuth2LoginView, OAuth2CallbackView located in allauth.socialaccount.providers.oauth2.views</li><li>And base provider classes that helps us to extract data from the partner: OAuth2Provider located in allauth.socialaccount.providers.oauth2.provider</li></ul><h4><strong>EXAMPLES OF CODE OF BASECAMP PROVIDER</strong></h4><p>Best representation of all neccesary changes could be viewed in the changed files of pull-request <a href="https://github.com/pennersr/django-allauth/pull/1077/files">https://github.com/pennersr/django-allauth/pull/1077/files</a></p><p>There are following changes:</p><ul><li>docs/providers.rst — add documentation with description where to register oAuth2 app, and where is full set of docs of the provider.</li><li>test_settings.py — add provider to the settings so when we run tests it automatically excecut e provider tests that we added</li><li>allauth/socialaccount/providers/basecamp — create a folder for the provider-related files</li><li>allauth/socialaccount/providers/basecamp/tests.py — add test for the provider</li><li>allauth/socialaccount/providers/basecamp/provider.py — create provider itself</li><li>allauth/socialaccount/providers/basecamp/views.py — create adapter for provider</li><li>allauth/socialaccount/providers/basecamp/urls.py — add adapter urls</li></ul><p>Core code is following:</p><p>django-allauth/allauth/socialaccount/providers/basecamp/views.py</p><pre>import requests<br><br>from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,<br>                                                          OAuth2LoginView,<br>                                                          OAuth2CallbackView)<br>from .provider import BasecampProvider<br><br><br>class BasecampOAuth2Adapter(OAuth2Adapter):<br>    provider_id = BasecampProvider.id<br>    access_token_url = &#39;https://launchpad.37signals.com/authorization/token?type=web_server&#39;<br>    authorize_url = &#39;https://launchpad.37signals.com/authorization/new&#39;<br>    profile_url = &#39;https://launchpad.37signals.com/authorization.json&#39;<br><br>    def complete_login(self, request, app, token, **kwargs):<br>        headers = {&#39;Authorization&#39;: &#39;Bearer {0}&#39;.format(token.token)}<br>        resp = requests.get(self.profile_url, headers=headers)<br>        extra_data = resp.json()<br>        return self.get_provider().sociallogin_from_response(request,<br>                                                             extra_data)<br><br><br>oauth2_login = OAuth2LoginView.adapter_view(BasecampOAuth2Adapter)<br>oauth2_callback = OAuth2CallbackView.adapter_view(BasecampOAuth2Adapter)</pre><p>django-allauth/allauth/socialaccount/providers/basecamp/provider.py</p><pre>from allauth.socialaccount import providers<br>from allauth.socialaccount.providers.base import ProviderAccount<br>from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider<br><br><br>class BasecampAccount(ProviderAccount):<br><br>    def get_avatar_url(https://medium.com/self):<br>        return None<br><br>    def to_str(self):<br>        dflt = super(BasecampAccount, self).to_str()<br>        return self.account.extra_data.get(&#39;name&#39;, dflt)<br><br><br>class BasecampProvider(OAuth2Provider):<br>    id = &#39;basecamp&#39;<br>    name = &#39;Basecamp&#39;<br>    package = &#39;allauth.socialaccount.providers.basecamp&#39;<br>    account_class = BasecampAccount<br><br>    def get_auth_params(self, request, action):<br>        data = super(BasecampProvider, self).get_auth_params(request, action)<br>        data[&#39;type&#39;] = &#39;web_server&#39;<br>        return data<br><br>    def extract_uid(self, data):<br>        data = data[&#39;identity&#39;]<br>        return str(data[&#39;id&#39;])<br><br>    def extract_common_fields(self, data):<br>        data = data[&#39;identity&#39;]<br>        return dict(<br>            email=data.get(&#39;email_address&#39;),<br>            username=data.get(&#39;email_address&#39;),<br>            first_name=data.get(&#39;first_name&#39;),<br>            last_name=data.get(&#39;last_name&#39;),<br>            name=&quot;%s %s&quot; % (data.get(&#39;first_name&#39;), data.get(&#39;last_name&#39;)),<br>        )<br><br><br>providers.registry.register(BasecampProvider)</pre><h4><strong>LINK TO PULL REQUEST AND CAMPSSORE</strong></h4><p><a href="https://github.com/pennersr/django-allauth/pull/1077">https://github.com/pennersr/django-allauth/pull/1077</a> — original pull request</p><p><a href="http://www.campscore.io/">http://www.campscore.io/</a> — A bit about project. It’s a dashboard that provides statistics for you BaseCamp account. You just have to signin with Basecamp account and it will show you amount of open/closed/peding tasks for specific dates you choose. So you can easily track performance of your team or your personal one.</p><p>2015–10–09</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5df859bbbc5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to have SVG allowed as an image for django-rest-framework]]></title>
            <link>https://medium.com/@7WebPages/how-to-have-svg-allowed-as-an-image-for-django-rest-framework-52772b972167?source=rss-60c4504736e------2</link>
            <guid isPermaLink="false">https://medium.com/p/52772b972167</guid>
            <dc:creator><![CDATA[7WebPages]]></dc:creator>
            <pubDate>Fri, 11 Mar 2016 13:17:07 GMT</pubDate>
            <atom:updated>2016-03-11T13:17:07.130Z</atom:updated>
            <content:encoded><![CDATA[<p>As you all know, svg is quite popular nowadays as a a format to serve images. If you use it, you are able to scale images enormously, thanks to its vector nature.</p><p>Here’s a schema of image upload logic with Django REST framework:</p><p>[[image-upload-logic-drf:class=left]]</p><p>Request comes to the DRF, next it’s validated via django.forms.ImageField (<a href="https://code.djangoproject.com/ticket/14092">which will not validate svg in the nearest future</a>), next data is pushed to the DB via models.ImageField.</p><h4>How to make SVG files valid at the form field level</h4><p>If you look at the to_internal_value method <a href="https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/fields.py#L1392">of DRF’s ImageField</a>, you’ll see that all validation occurs when</p><pre>django_field.to_python(file_object)</pre><p>is called.</p><p>As you can see <a href="https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/fields.py#L1400">here</a>, there’s an option to provide another validator as an argument when you define Serializer:</p><pre>class SomeSerializer(serializers.ModelSerializer):<br>    image = ImageField(required=False, _DjangoImageField=SVGAndImageFormField)</pre><p>and voilà — you can pass validation with svg files. Probably, you’re guessing “oh, where can I get SVGAndImageFormField?”</p><h4><a href="https://gist.github.com/ambivalentno/9bc42b9a417677d96a21">HERE</a>.</h4><p>As you can see, it’s a slightly modified version of django.forms.ImageField.</p><h4>Workaround for ORM layer</h4><p>But one more issue is still there — you’re not able to put svg file into models.ImageField because of <a href="https://github.com/django/django/blob/master/django/db/models/fields/files.py#L423">dimensions</a> that don’t exist in svg file — it can be scaled to any size. As a workaround, I’ve just switched from models.ImageField to the models.FileField in django models.</p><h4>TL;DR</h4><p>To be able to upload/use svg images with Django Rest Framework you shoud perform next steps:</p><ol><li>Switch your model’s ImageField to the FileField (don’t forget to migrate!).</li><li>Grab <a href="https://gist.github.com/ambivalentno/9bc42b9a417677d96a21">the gist</a> and put it somewhere in your project.</li><li>Import SVGAndImageFormField to the file with your serializers from the gist file. Import ImageField from rest_framework.fields.</li><li>Update validation in your serializers:</li></ol><pre>image = ImageField(required=False, _DjangoImageField=SVGAndImageFormField)</pre><ol><li>PROFIT!</li></ol><p>Author: <a href="https://www.facebook.com/khliestov">Nick Khlestov</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52772b972167" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>