Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Djangocon: Conformity and you - a question of style - Greg Chapple
(One of the summaries of a talk at the 2015 Djangocon EU conference). Greg Chapple works half his time on Django projects, half on Rust projects. Some things you'll probably never hear: "Can't wait to fix some pep8 violations today". Style conventions probably aren't the sort of thing you take into account when picking a language or a framework. Every line of code follows some sort of style convention. Intentional or not. The style of our code can identify us. Same as with this talk: Greg speaks with a slight Dublin accent, by default. Something to ask yourself: if you look at a piece of code inside your company, could you identify the person that wrote it? Let's get back to Greg's accent and the way he speaks. How did he come by this? Where he grew up, of course. The people he's around regularly. You can change it, though. He spend two weeks in the USA and when he came back he got funny looks for some of the US pronouncement that krept into his vocabulary. The same with your code style! You're influenced by the code you're surrounded by. If you want to make changes, it takes quite … -
Djangocon: Lightning talks
(One of the summaries of a talk at the 2015 Djangocon EU conference). Pycon Namibia - Daniele Procida In february 2015, the python conference in Africa actually took place! In Namibia! Daniele Procida talked about the plans at many conference (like at djangocon.eu 2014). It was really good. They formed valuable relationships and learned a lot. Several of the attendees are here at the conference. They're going to organize another conference later this year. So if you want to escape a dreadful European winter... I'm new to django but why should I use it? - Ben Sharif Why should you use it? You're new, so why Django? He's in that situation. He's a medical student. He's not a doctor yet. It also means he isn't a professional programmer. He wants to quickly prototype ideas for medical web apps. He wants something that lets him develop things fast: Django fits the bill. He started learning python in may 2014. He tried the django tutorial, but that didn't really work. He got pointed at web2py. Easy to get started. Almost no configuration. Through the web development. His demo is at http://medboard.co.uk/ So... what is he missing? The django community is absolutely massive. … -
Djangocon: Django aggregations demystified - Theofanis Despoudis
(One of the summaries of a talk at the 2015 Djangocon EU conference). Theofanis Despoudis started out as a PHP (Pretty Horrible Pages) developer at first. He's a recent python enthousiast. Aggregations are basically database functions. Django abstracts away the details behind a simple function. It is useful for producing summaries over collections of objects. Stuff like average, maximum, minimum, sum, count, standard deviation, variance. There is probably more on the database level, but this is the list that django supports. He showed a couple of examples like Gamer.objects.all().aggregate(num_wins=Count('won')). It translates to a quite well optimized SQL query. With django, you don't have to do this by hand. Annotations is a second way to generate summary values. The difference is that it doesn't aggregate all the objects, but that it adds the summary value to every individual result. So instead of the total number of games won like in the aggregate example, you can now add an extra 'column' to every individual result like this: Gamer.objects.all().annotate(num_wins=Count('won')) Nice: you can also slice and order on annotations. You can order the above results by num_wins and pick the highest 5: Gamer.objects.all().annotate(num_wins=Count('won')).order_by('num_wins')[:5] You can also combine annotations with automatic grouping by calling .values(). … -
Djangocon: Into the rabbit hole - Ola Sendecka
(One of the summaries of a talk at the 2015 Djangocon EU conference). Ola Sendecka organized the Warsaw djangocon in 2013 and started the djangogirls organization. She told us a story in which she paraphrased "Alice in Wonderland" as "Alice in Djangoland" :-) Complete with code examples. Fun. Alice's sister asked her to have tea with her. "Fine, I'll be there in 10 minutes". And she starts adding a small feature. But ran into a small problem. Oh, I'll fix that with a small change to the object manager. "Are you coming for tea now?". Yeah, almost done. I just need to fix this small bug in the new code. So she had to make a small modification to override something in the form layer. Oh. Traceback. "The tea is getting cold". I'll just override something in a the form field. And some extra customization there. In the end, the code was horrible. And Alice's sister was angry. What happened? Good question! The problem: Alice was in a rabbit hole. She got so caught up in what she was doing that she just kept doing that for hours on end without really getting anywhere. You fall into a rabbit hole … -
Djangocon: Give your pony wings - Benjamin Wohlwend
(One of the summaries of a talk at the 2015 Djangocon EU conference). Benjamin Wohlwend confesses that he's a lazy programmer. He also likes his code to be lazy: he doesn't want his code to do too much. Why? Code that doesn't do much is code that is fast. If you have performance problems, how do you find them? He uses django-debug-toolbar and django-devserver a lot. django-debug-toolbar is great, especially because it lists the number of queries (which is a common performance problem). django-devserver also prints out the number of queries and the time it took. For every request. Handy. It is a runserver replacement. To reduce the number of queries, django provides select_related() and prefetch_related() Select_related is for immediately grabbing related objects in one big query. prefetch_related does something similar, but it is better suited for many-to-many fields and reverse foreign keys. There are many more tricks. You can use django's annotate function to let the database count numbers of related objects instead of grabbing them all. Much quicker. Also .defer() helps, this lets you tell django not to grab certain columns as they're not needed. Caching can make your code way faster. But cache invalidation is hard. It … -
Djangocon: Django's role in the polyglot web - David Gouldin
(One of the summaries of a talk at the 2015 Djangocon EU conference). (You can also see this presentation by David Gouldin on https://django-polyglot.herokuapp.com/ ) Django is 10 years old now. It is not a cms, but it was originally build for one. 10 years? The web in 2005 was much different from the web we know now. If you were a developer in 2005, you'd have a relational database and some php and an apache in front. Now there are many more parts. And on the server side often there are various parts that need to be connected. And... are you building a website or isn't it more like a real-time webapp? Ok, where does this all leave django? Django is well-placed! Django is build in python. Don't underestimate that advantage! It gives us a huge advantage over frameworks that use less mature n Django is build for "perfectionists with deadlines". One of the places where this shows up is the ORM. You can say about it what you want, but it works well and it enables the django admin, which can be a great timesaver. Django rest framework. Very easy to make good APIs. Celery. Easy to use. … -
Djangocon: Local development with docker - Stefan Foulis
(One of the summaries of a talk at the 2015 Djangocon EU conference). Stefan Foulis did a live demo, so he first sacrified something to the demo gods by doing rm kitten1.jpg, rm kitten2.jgp :-) What is docker? It is kind of like a virtual machine (sort of), but much more efficient. Without emulating a whole machine. The launchtime is milliseconds instead of seconds or minutes. Some terminology: Image. A read-only "template" like a snapshot of a virtual machine. Images can be layered. A django image can build upon a python image that builds upon a debian 8 image. Container. An instantiated image. Like a running virtual machine. Registry. A repository of images. See for instance https://hub.docker.com/ and search for python and django. Instructions to docker go into a "docker file". In it you specify a base image and further instructions like packages that need installing, directories that need to be made, the main working directory and which program to start up as the one single main program that is run inside the docker container. With docker compose, a yaml format, you can "compose" containers. This means you can run multiple containers at the same time, for instance a postgres … -
Djangocon: Web accessibility is not optional - Xavier Dutreilh
(One of the summaries of a talk at the 2015 Djangocon EU conference). Xavier Dutreilh says the web played a big part in our lives. It shaped us. For the most part we're happy with the web and we don't see any real problem with it. But there are problems. An important problem is because we design websites for non-disabled people. So we exclude lots of people with disabilities. It might sound harsh, but it is the simple truth. What is web accessibility? It is the inclusive practice to remove barriers from websites. It ensures everyone has equal access to the information. What is a disability? It is an impairment, either present from birth or acquired later. Either due to an accident, sickness or a genetic condition, for instance. An impairment can be eigher progressive or non-progressive. There are four main categories: Visual. Blindness, low vision or color-blindness. Technically, when you have to wear glasses, you fall into the low vision category. Hearing. Deafness or hard-of-hearing. Motor. Limited dexterity or loss of limbs. Cognitive. Learning issues or memory loss, for instance. So, how do you do web accessibility? The first thing is to provide appropriate alternative text for non-text context. … -
Djangocon: True beauty is on the inside, but users are shallow - Loek Van Gent
(One of the summaries of a talk at the 2015 Djangocon EU conference). Loek Van Gent has done lots of php/zend work for many, many years. Now python/django for 3 years. He is a member of the 1% club, they support small initiatives that help change society, a "do-good crowd funding platform". They went from two separate sites to one site that could be used as a white label/multi-tenant site. It took quite some engineering effort. And they also made a couple of UI changes, more or less 2% of the work. The boss's reaction? "Wow, I love the new design, great job". The title of his talk is "true beauty is on the inside, but users are shallow". In this case, the boss was shallow and only looked at the the outside, even though 98% of the work was on the backend of the website. Nothing really wrong with that. It underscores the importance of how something looks. He demoed the creation of a django project. A site and two apps. Each app of course has a template/ and static/ directory. But you shouldn't do that. At least according to the 1.8 edition of "2 scoops of django". You … -
Djangocon: Using Python to load-test web apps - Yulia Zozulya
(One of the summaries of a talk at the 2015 Djangocon EU conference). Using python for your load testing is handy. You use the same language that you use for development. You can more easily write small functions to help you. FunkLoad is often used. You configure it with a text file. You can fire off requests from separate tests. You can configure the various treads to have a startup delay and delays between individual requests. Handy: Funkload classes are inherited from unittest.TestCase. They are easy to understand and write. You can use them as smoke tests with simple unittest runners. You can even distribute the benchmark over multiple machines in a testing environment. It is also very well documented and extensible. Funkload also has drawbacks. It uses python's default threading module, which means you're probably not using all your machine's power. The tool itself is configurable, but the default reports are not. And they're not very nice. Multi-mechanize is an alternative. It uses multiprocessing along with threading, so you really use your machine's power. The default reports are more configurable. It also has drawbacks. The API is not as obvious as Funkload's. And distributed workflow isn't supported. A third … -
Djangocon: Using Django in a desktop application - Thomas Turner
(One of the summaries of a talk at the 2015 Djangocon EU conference). Thomas Turner has been using Django for the last 7 years. His company Joinerysoft made a desktop app build on django for joineries ("window makers"). What they use includes Python/Django. MFC, microsoft foundation classes. DHTMLx. ReportLab for PDF report generation. Firebird SQL database. Why django? It is future proof. Easier to connect to the internet. And html pages are often more beautiful than standard microsoft dialogs. A problem was securing the python and html code. They didn't want customers to modify the templates, so they wrote their own template loader that could read encrypted templates. Same with python files. They shipped encrypted *.pyc files. For that, they needed to modify django a bit, because it looks for *.py extensions in various places. As webserver, they settled on cherrypy which ran fast enough and could be integrated into c++. As database, they picked Firebird as that one was easy to install and performed fine. As a browser, they picked CEF (Chromium Embedded Framework), basically an embeddable version of Chrome. It is used by spotify, steam client, github for windows and adobe dreamweaver. You can embed it into a … -
Djangocon: The full stack octopus - Kat Stevens
(One of the summaries of a talk at the 2015 Djangocon EU conference). Kat Stevens is the sole web manager at her wine company. So she needs to be an octopus with many arms to do all the tasks. Django, bug fixing, sysadmin, installing, planning, etc. When she started working there she found a 7 year old .net legacy site. She had the freedom to choose whatever she wanted and she picked Django. She had not programmed python before, so she started with small prototype projects to test everything out. Python/Django Django is the favourite part of the stack for her. She loves that it is open source so that she could inspect the code to see exactly what it was doing. Custom template tags are great, for instance for doing currency conversion. The site is quite big now, so she can lose track of things somewhere. If you're the only one working on a big codebase... Another drawback of working on your own is that you don't hear a lot about nice tools. Django debug toolbar was one of the tools that she discovered pretty late, but can't work without now. Nice: she only has to merge code with … -
Djangocon: Lispisms - Shai Berger
(One of the summaries of a talk at the 2015 Djangocon EU conference). Shai Berger is a member of the django core team. Lispisms? Those are concepts you could import from Lisp into python. Lisp is invented in 1960, it is ancient. (All (your (code (is (full (of (parentheses))))))).. Many important concepts were invented in lisp. Garbage collection, recursion, dynamic typing. So: have we gotten everything that is useful out of Lisp? Or are there still gems hidden that we can use? What about dynamically scoped variables? People have been asking for ages for the request object to be available globally and they always got the same answer: GLOBALS ARE EVIL. Their value changes unpredictably because everybody anywere can modify them. You can get some of the way with thread-locals. But why is it evil? The fact is, it is very convenient. There are other places where we effectively do it, for instance we don't need to pass the database connection object into every query... Is it possible to use globals that behave themselves? Where every change is temporary, only passed down the call chain? A bit like a 'with' statement. This is the default in lisp. You can modify … -
Djangocon: Forms are not static - Markus Holtermann
(One of the summaries of a talk at the 2015 Djangocon EU conference). Markus Holtermann works on the django core team. Forms are basically there for input validation. They're also used for rendering actual web forms. Normally, forms are pretty static. The field are there and they don't change. But sometimes you want for instance request dependent forms. Depending on the request, some fields might be left out or are added. The same way, depending on the permissions of the user, there might be more or fewer values in a dropdown. Markus would say that those forms are still static, because you have to write code to make those kind of changes. He was involved with a website that dealt with different events. Every event needed a form with slightly different fields. With regular static forms, you'd need to create a fresh new form class a couple of times a year. Not nice. He ended up making django-dynamic-forms that could construct forms on the fly. Django itself dynamically creates forms when you use ModelForms. It reads the model and dynamically creates a class. You can do that in python with type(). He does basically the same, but he doesn't read … -
Djangocon: Effortless real time apps in Django - Aaron Bassett
(One of the summaries of a talk at the 2015 Djangocon EU conference). Aaron Bassett says there are two kinds of polling you can do upon http: lots of small requests all the time, hoping that there's something new on the server. And "long polling", where a connection is opened and kept open until the server has something to send back. Once received, a new http request is send out. But... in the core, that's a hack. http isn't designed for that. Now there's websockets. Persistent connections where you can send messages back and forth between server and browser. There is a django package to make real time web easy: swamp dragon. Swamp dragon consists of: Redis. Basically a very quick, persistent kind of memcache. Supports pubsub. Tornado. A python webserver. Non-blocking IO. Lots of connections are no problem. Django. Swamp dragon takes care of all the real time stuff for you. He made a sample TODO django app. Some notes: There's a swamp dragon model mixin that makes sure any changes to the models are send to Redis. You have swamp dragon serializers that tell which data you want to extract from the models. And you can add extra … -
Djangocon: lightning talks day 2
(One of the summaries of a talk at the 2015 Djangocon EU conference). (These talks only take 5 minutes, so I'm bound to miss things, especially names. If something needs correcting, just post a comment below or mail me at reinout@vanrees.org ). Django under the hood 2015 This year django under the hood happens again. It'll be bigger, so there'll be more tickets so that it probably won't sell out in about 4 minutes again. http://www.djangounderthehood.com/ It is in november. 1.5 day of talks and a day of sprinting. Detailed talks, for instance about all the details of an http request or about django's security measures or about files in django. Djangocon Europe 2016 Djangocon Europe 2016 will be held in.... Europe! We don't know yet where it will be, though. They are still looking at the proposals. If you're not ready, but might want to do it in 2017: the plan is to let one or more people from 2017 help organize 2016 to help with knowledge transfer. Django and robotic telescopes - Edward Gomez He works at http://lcogt.net/ and normally speaks to astronomers or school kids. They have a network of 12 robotic telescopes all over the world. … -
Shanley and my PyCon talk
A few folks have asked about a link between my PyCon talk and Shanley’s writing, specifically her essay 10x Engineer, which you can find in her essay collection, Your Startup Is Broken. Shanley’s writing (and the work she publishes in Model View Culture) has influenced and inspired my thinking about the tech industry in many ways. Shanley’s writings on tech and feminism have informed and inspired me, and have definitely helped shape my thinking. -
Djangocon: Pushing the pony’s boundaries - Ola Sitarska
(One of the summaries of a talk at the 2015 Djangocon EU conference). Ola Sitarska absolutely loves the django admin interface. She started out writing elaborate admin interfaces for silly games in PHP. At a certain moment she discovered django and hasn't written a single line of PHP since. She organized djangocon.eu 2013 and djangogirls and she's a core developer and.... she even named one of her cats "django" :-) The django admin is not one of the most beautiful parts of the django code base. It is hard to wrap your head around the code at first, but it is very robust and backwards compatible. In the end it are just a couple of views and urls, though. Three important classes are AdminSite, ModelAdmin and Changelist. Insides of the admin AdminSite: encapsulates one instance of the django admin pages. If you add /admin to your urls.py, you're effectively instantiating an AdminSite. Which means you can do it yourself by hand, too. With a different name and different behaviour. .get_urls() is an important method. It sets up the urls, for instance for login and logout. And it iterates over all registered models, ading urls for them. There's also some basic … -
Djangocon: Cardiff
(One of the summaries of a talk at the 2015 Djangocon EU conference). Conference introduction Some noteworthy items from the introduction: There's a creche! So people with small children also can come. No water bottles. Well, actually, everyone got a aluminium wateter bottle, hand-washed by the conference chair :-) You think I'm typing fast for these summaries? There were two live speach-to-text typists that provided live subtitles on a couple of monitors! Wow. Handy for those with hearing problems and for those whose first language isn't English. Cardiff University wellbeing service The cardiff university's wellbeing service offers help during the conference. For instance with managing stress and other common workplace difficulties. Also advice with physical and emotional wellbeing. Think about the top 5 most important items in your life. If you'd draw it as a pie chart, how much would you allocate for every one of them? Is there for instance a 'work' segment that takes up 70%, drowning out the rest? Wellbeing is linked to increased productivity in work and improved work performance. More than 40% of persons have problems that impact their work productivity! Work intruding on the rest of their lives, for instance. Or a sedentary lifestyle … -
Djangocon: Injecting Django into the work environment - Abdulrahman Alotaibi
(One of the summaries of a talk at the 2015 Djangocon EU conference). Abdulrahman Alotaibi started studying in 2008 and started using linux (the "LAMP" stack). In 2009 he discovered Python and in 2011 he started using django. At the time he debated whether to use django or ruby. A pycon talk by one of the django core developers about "snakes and rubies" swung him over to django. He now lives in Kuwait again and is involved in the open source community there. Almost everything at his company/research center was closed source. The solution was to try to enforce it with a "constitution". Enforcing version control and so. And reproducible builds. But forcing it isn't enough and it doesn't work. So they started giving courses, for instance in using git. And mandating use of virtual machines so that the work environments were more or less the same. This phase was followed by the actual work of collaboratively building several django websites. Sometimes they figured out they needed to change their "constitution" or their tools. Core to the success to go back and forth in the process. First a constitution, then courses, then back to the constitution, then work, then back … -
Djangocon: Avoiding monoliths - Hanna Kollo
(One of the summaries of a talk at the 2015 Djangocon EU conference). Hanna Kollo talks about one of the biggest anti-patterns in software development: monoliths. She works at spilgames, where they use lots of django and python. The load sensitive components are written in Erlang, but the internal tools are mostly python/django. She works mostly on the internal tools. It are business-driven applications, so they have changing requirements and it is a huge challenge to keep the code clean. If you don't watch out, you end up with one monolithic piece of code. A monolithic django app is one app. No modularity. One models.py, once set of views. Spaghetti code: everything is connected to everything. (Note: often a monolithic application is described as not having multiple layers. She looks at it more from a django viewpoint.) Monoliths are hard to understand. It is hard to make changes. Hard to reuse. Hard to decide what impacts what. The example she gave was about an internal publishing project. Basically a CMS for games. They designed a strong architecture: a modular structure. Enforced. Many small aps. She showed the dependency graph: it was one big hierarchy of apps. This wasn't a monolith, … -
Djangocon: Baptiste's adventures in Djangoland - Baptiste Mispelon
(One of the summaries of a talk at the 2015 Djangocon EU conference). Baptiste Mispelon spend 2014 roaming around in djangoland. Djangoland? Esperanto is a language invented by Zamenhoff, a polish guy. There's a "Esperantujo" concept: "esperanto-land". Once you meet someone who speaks that invented language, you're in esperanto-land. It is the same with django. Once you meet people who program django or if you're on the IRC channel, you're in djangoland. He told a bit about his history. Dropped out of school in France in 2009 and moved to Hungary towards his girlfriend. After a period of doing nothing, he started making php websites. Afterwards he discovered python. He attended the djangocon in Zürich (2012). His first conference. He stayed for the sprint: this was the best decision of his whole career. He met lots of people and felt welcomed. And learned a lot. A couple of months later he got in his first pull request to core django (a one-character documentation fix). In 2013, he started diving deeper and deeper into the code and solving more and more issues. He attended djangocon again, the "django circus" in Warsaw. Because of his many patches, he got invited to join … -
Djangocon: Reaching out, Django in the social sciences - Lucie Daeye
(One of the summaries of a talk at the 2015 Djangocon EU conference). Lucie Daeye is a social scientist that just picked up django last year. But she already organized a django girls paris event and is busy getting a PyLadies Paris started. For her research, she has to keep all sorts of data on restaurants. Addresses, text from interviews, other data. She thought there would be already software for that. Something with automatic address import, perhaps automatic simple maps, easy way to add notes, etcetera. She asked her professor for the name of the software she needed to download and he said "use a spreadsheet". Ouch. No. Back to paper? All kinds of papers in multiple folders? No... She asked other PhDs for what they're using. Basically electronic files in lots of remote folders... She complained to a developer friend who pointed her at Django. She got something simple working with the django admin. A single "Restaurant" model. Now she wanted to have a map. Which meant she actually had to program. She saw that there would be a one-workshop for woman that wanted to learn programming (djangogirls). One one-day workshop and 10 hours of work afterwards and she … -
Djangocon: Salt for django developers - Yann Malet
(One of the summaries of a talk at the 2015 Djangocon EU conference). Yann Malet is a co-author of high performance django. He now talks about salt, a tool for configuration managament and remote server setup. First some terminology, which might not be clear for non-english speakers. Master: the main machine that steers the whole process. Minions: the "slaves", the machines that are managed by the master. You can run commands and so on those minions. You don't need to do it on all of them, you can target specific groups like "os.ubuntu" or "role:web". He showed a couple of commandline examples like adding users and keys to a fresh system. Pillar: a set of variables for one or more minions. Look at it as a python dict. Grain: where pillar is more for multiple minions, grains are for one specific minion. It is the static data collected from the minion, like the amount of memory in the machine. In the end, the various information for the minions is all squashed together, based on the roles the minion needs to have. The total state is then pushed to the minion and applied. The easiest way to do custom stuff, like … -
Djangocon: Switching from nose to py.test at Mozilla - Mathieu Agopian
(One of the summaries of a talk at the 2015 Djangocon EU conference). Mathieu Agopian likes py.test much more than regular python unittests or nose. A bit of terminology. A test is a piece of code written to assert that another piece of code is behaving as expected. Test runner: gathers test and runs them. Test suite (or "a built"): full collection of tests to run. py.test is already quite old and it is now maintained by a big team. One of the handy features is tests written without boilerplate. assert 1 + 1 == 2 works! No need for self.assertEquals(). There is a plugin system. Like nose, it doesn't show output if the test runs OK. If a test fails, py.test provides awesome error reports. "This item misses from the second dict" instead of only showing the two dicts, for instance. Test fixtures are done via dependency injection: you just pass a fixture to the test function. No need for testSetup() and testTeardown(). You can run the same test with multiple parameters. Plugins? For instance pytest-django, which runs createdb for you. pytest-cache is another good one. It allows you to run the tests with the --lf, "last failed", option. …