Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Generate Sphinx Friendly Docstrings For Python Functions In Emacs!
Today, I went to Django REST Framework Workshop. After the workshop is completed, and we were discussing about Emacs, Krace showed this cool plugin sphinx-doc, it inserts docstring skeleton for Python functions/methods as per the requirement of the Sphinx documentation generator.Installation:To install it from MELPA, run "M-x package-list-packages", search for "sphinx-doc" , mark it with i and press x to install.Configuration:Add these lines to Your emacs config to enable sphinx-doc-mode.(add-hook 'python-mode-hook (lambda () (require 'sphinx-doc) (sphinx-doc-mode t)))If you document your code(infact you should), this plugin saves quite a few strokes! -
Quickly Check If Your Django App Is Ready For Production!
Before deploying Your Django app, You need to make sure security, logging and other issues are taken care. Django provides a simple deployment checklist which helps a lot. In development version Django provides --deploy option, which does some security checks. You can run it withpython manage.py check --deploy --settings=production_settingsI have just created a new project and Django identified 6 security issues in it.→ python manage.py check --deploy System check identified some issues:WARNINGS:?: (security.W001) You do not have 'django.middleware.security.SecurityMiddleware' in your MIDDLEWARE_CLASSES so the SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_BROWSER_XSS_FILTER, and SECURE_SSL_REDIRECT settings will have no effect.?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE_CLASSES, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF token.?: (security.W017) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE_CLASSES, but you have not set CSRF_COOKIE_HTTPONLY to True. Using an HttpOnly CSRF cookie makes it more difficult for cross-site scripting attacks to steal the CSRF token.?: (security.W018) You should not have DEBUG set … -
Naming things: don't use reserved words
I'm currently cleaning up some code. Some people just cannot spell "p-e-p-8" if their lives depended on it, apparently. Luckily I'm civilized so I only threaten with dismemberment. Look at this gem I just uncovered: tg_after = instance.filter.technischegegevensfilter_set.exclude( pk=instance.pk).filter( datum_vanaf__gt=instance.datum_vanaf).order_by( 'datum_vanaf')[:1] Don't mind about the Dutch in there. Just look at those two filter words in the first two lines. They're even nicely underneath each other. At least they are now, I first had to fit the 159 characters long line within 78 characters, of course. In Django, you do sql filtering with .filter(some_condition=42). That's not what's happening in the first line, though. There's a foreign key called filter there! So the first filter is the name of a foreign key and the second filter is the filter method that is used everywhere in Django. Big confusion. And big chance that someone else that reads the code messes it up somehow. So... steer clear of common words used in your programming language or framework or whatever. Some examples: Don't use type as an name. Use customer_type or station_type or whatever. Only use type by itself if you really mean the python build-in. Don't use class. Either use the standard klass … -
Introducing django-nocaptcha-recaptcha
Introducing django-nocaptcha-recaptcha -
Build a scalable Twitter clone with Django and GetStream.io
Have a look at this tutorial on how to build a scalable twitter clone using django and getstream.io Share and Enjoy: -
Build a scalable Twitter clone with Django and GetStream.io
Build a scalable Twitter clone with Django and GetStream.io -
Building a RESTful API with Django-rest-framework
API's turned to be the heart of every application in our time. With the rise of social media, API's are being developed at a faster pace and gaining a lot of attention. Gone are the days where RPC architectures like CORBA and XML-RPC are used to enable the exchange of information and REST has taken its place making its mark in getting the things pretty straight forward. We use APIs in our everyday life. Take an instance booking a ticket for a movie through some website. Here is the process that takes place in the background. When dealing with the payment for the ticket, the website connects to the bank and sends your credit card details to the remote application and it gets verified. And once, the payment is confirmed by the remote application, it sends a confirmation response to the movie booking website to issue the tickets. The payment stuff turned possible here as the bank facilitates an API through which a website can connect to it and deal with the payments which resulted us an effective and seamless transaction. In this post we will get to know how to build a Restful API for an application using a … -
Caktus Hosts Lightweight Django Book Launch with Girl Develop It
With Girl Develop It RDU, we celebrated the launch of Lightweight Django (O'Reilly) with the authors, Caktus Technical Director Mark Lavin and Caktus alum Julia Elman. Sylvia Richardson of Girl Develop It MCed. The event was open to the public and so popular we kept recounting the RSVPs and fretting over the fire code. But, phew, we were good. In attendance were friends, family, fellow Cakti, and Django fans from around the Triangle. Festivities included lots of Mediterranean food, some of Mark's favorite beers, raffled-off gift bags filled with Caktus goodies, and, for those in the first two rows, free copies of Lightweight Django. The main attraction, of course, was hearing Mark and Julia speak. In response to audience questions, they both emphasized code quality with Mark highlighting the importance of iteration in any process. You can read more about their very strong opinions in Lightweight Django. (See what I did there? I totally just encouraged you to buy it. Go buy it!) They also spoke about the ups and downs of writing, the doubts, and the ways they egged each other on. There too was the challenge of working on client projects full time, writing the rest of the … -
Caktus Hosts Lightweight Django Book Launch with Girl Develop It
With Girl Develop It RDU, we celebrated the launch of Lightweight Django (O’Reilly) with the authors, Caktus Technical Director Mark Lavin and Caktus alum Julia Elman. Sylvia Richardson of Girl Develop It MCed. The event was open to the public and so popular we kept recounting the RSVPs and fretting over the fire code. But, phew, we were good. In attendance were friends, family, fellow Cakti, and Django fans from around the Triangle. -
Loading Django FileField and ImageFields from the file system
Loading Django FileField and ImageFields from the file system -
FreshDesk Python API
FreshDesk is a great helpdesk system with a fully functional API. Recently a client asked to integrate FreshDesk into their Django based CRM. I created the Python interface to the API. Here's the gist. -
Parse cloud code, EmberJS & GetStream.io
Today we’ve released a small example app, which shows you how to integrate GetStream.io with Parse cloud code. The example is based on EmberJS and listens to changes in realtime. The demo shows a simple Facebook/Twitter style network where you can Share your View. Go ahead, try the demo and post a nice shot from the city you’re in right now.https://getstream.parseapp.com/#/ The cool bit here is that Parse Cloud code allows you to connect to other hosted platforms. In this case we’re integrating a scalable newsfeed with getstream.io, but you could for instance also hook up something like Algolia for search. The code for the integration, with explanations of how we’re using the Parse Cloud code can be found on Github/getstream/Stream-Example-ParseLet us know in the comments which other integrations you’d like to see. So far our Django, Rails and Laravel integrations are making it extremely easy to integrate a scalable newsfeed in your app. -
Django Dash & WSGI Wrestle Cancelled
Django Dash & WSGI Wrestle Cancelled -
Project Templates with Cookiecutter
When we start new projects we want to solve a problem, not write boilerplate. Cookiecutter helps you to stop writing boilerplate. In this video you will learn what cookiecutter is, and how to create templates so you can save yourself time and effort starting new projects.Watch Now... -
Handling Django's get_query_set rename is hard
Handling the rename of get_query_set to get_queryset in Django 1.6 is very tricky - much trickier than it might seem. For many 3rd party libraries, you will have a few aims: Maintain compatibility with older Django versions, and older projects (including libraries) that might call your code, or subclass it. Update your code to be compatible with latest versions of Django Stop getting warnings when running your code/tests. Warnings you've already addressed are a pain, as they drown out the ones you haven't addressed. Subclassing makes this much, much harder. Suppose you have: class FooManager(models.Manager): def active(self): return self.get_query_set().filter(active=True) def get_query_set(self): return FooQuerySet(model=self.model) How do you update this code? The tricky bit is that you need to consider a class that subclasses FooManager, which you don't control. That code might not be updated yet. A very important example is the RelatedManager class in Django, which dynamically subclasses the default manager on a model to provide access to related objects. You use this all the time, in ORM calls like person.schools.all() — roughly speaking schools returns a dynamic subclass of School.objects. In Django 1.5, this subclass overrides the get_query_set method so that it calls super.get_query_set (e.g. School.objects.get_query_set) and then adds some … -
Recommended Django Project Layout
Recommended Django Project Layout -
Summary of my "developer laptop automation" talk
Last week I gave a talk at a python meetup in Eindhoven (NL). I summarize Therry van Neerven's python desktop application development talk, but I didn't write one for my own "developer laptop automation" talk. Turns out Therry returned the favour and made a summary of my talk. A good one! -
Katie learns Angular.js
December 1st, I’m starting a new gig at SpeakAgent. A major part of the stack involves Angular.js, something I hadn’t really taken a hard look at before now. Sure, I’d heard the front-end devs chat about it, but it never occurred to me take a look. This series isn’t going to be a tutorial. If you’re looking for that, I’ll be keeping a list of resources that helped me greatly along the way. This is more a journal of learning, akin to my unfinished Roguelike series. Once again, I’m going to make a wee game. The idea is to revisit a previous project: Ten by Ten. The idea is to create a framework for making text adventure games. Some sort of Python framework (probably Django) will hold all the model data while Angular will control the the logic and presentation. What is AngularJs? Angular is an MVC framework written in JavaScript. Its primary aim appears to be making the creating of web applications less painful. I suppose I’ll be putting that to the test! Why not just jQuery? Well, first off, it’s what my new gig is using, so I’m learning it. Also, from what I can gather, Angular is … -
Uber and the Fourth Estate
Context: Uber Executive Suggests Digging Up Dirt On Journalists, The moment I learned just how far Uber will go to silence journalists and attack women. An old adage: “never pick a fight with someone who buys ink by the barrel”. Ignoring it, Uber shows they’re not just evil - they’re stupid. — jacobian (@jacobian) November 18, 2014 It’s more than an old adage, though: in targeting journos, Uber shows its utter contempt for even the concept of accountability. -
Easier integration with new API clients and data browser
In the past days we’ve updated our API clients for Python, Ruby, Node and PHP. Thanks for the great feedback which helped us made the API easier. Client improvements One thing which confused many new users was the syntax for getting a feed object. In the old syntax we would write client.feed(‘user:1’), which gives you access to the feed named “user” for user id “1”. Dozens of people emailed us with questions about this syntax. It was especially confusing that you have to setup the “user” part in the dashboard, but the user_id part is automatically created. The new syntax client.feed('user’, '1’) clarifies that there are 2 different arguments. The follow syntax has received a similar update, ie: flat1.follow('user’, '1’). You can use the new style syntax by upgrading your client library to the latest version. Framework integrations Furthermore we’ve added python 3 support to the Python client and Parse cloud support to the js client. In addition the framework integrations for Django, Rails and Laravel received a big cleanup. Data browser Last, we’ve released the data browser, which is a really nifty little debugging tool when you’re developing your application. You can access it via the dashboard. What’s next … -
Disqus and Disqus SSO
Outsourcing the comments and discussions part to a third party widget always helps us to save a lot of effort. When you feel that if it is okay to share your thoughts and discussions with someone out there who serves the capabilities of social integration and spam detection won't it be a cake walk? Disqus is such a kind of blog comment hosting service which is platform-agnostic and URL-agnostic. It is built with javascript and backend technology, Python using Django. Let us get to know how to add this to our Django app. Adding Disqus widget to a site is pretty straight forward and effortless. Here are the steps to follow: Create an account on Disqus and fill the details at https://disqus.com/admin/create/ Once you finish registration, access the universal code In the next following page, get the script and use it wherever we want to display comments Update the settings file with DISQUS_SHORTNAME The first step includes signing up in to Disqus and getting an account. Once we are done with it, we will be heading to a home page where we can find "Add disqus to your site" on top left. If we click it, we will be redirected … -
Bad Request 400 and Django Debug
Bad Request 400 and Django Debug -
Django under the hood: Django ORM - Anssi Kääriäinen
(One of the summaries of a talk at the 2014 django under the hood conference). Anssi Kääriäinen is the "guardian of the ORM", he knows where all the bits and pieces are. He'll explain especially how QuerySet.filter() works. What is the Django ORM (object relational mapping)? It is a: Query builder. Query to object mapper. Object persistence. The operations the django ORM does are higher level than SQL by design. It doesn't have .join() and .group_by() operations exposed as an ORM operation. It'll do them behind the scenes, but you can't call them directly. Now about filters. For instance: Book.objects.filter(author__birth_date__year__lte=1981) This grabs the books with an author with a birth date's year that's 1981 or earlier. That year in the query isn't in django by default. Something new in django 1.7 are model transforms. This allows you to add such a specific year loookup: @some_registration_decorator class YearTransform(models.Transform): lookup_name = 'year' output_field = models.IntegerField() def as_sql(self, compiler, connection): # Some nice code that returns a bit of SQL Book.objects.filter(author__birth_date__year__lte=1981), what does it mean? Book is the model class. objects is the manager (models.Manager) filter is a method on the manager. It returns a models.QuerySet. It results in a models.sql.Query, which is … -
Django under the hood: django REST framework - Tom Christie
(One of the summaries of a talk at the 2014 django under the hood conference). Tom Christie will give a two-part talk. The first is about django REST framework, the 3.0 beta will be out tomorrow. The second part is about API design in general. REST framework 3.0 They made a few fundamental changes in 3.0. Why did they do this? For instance for serializers. Serialization is from an object to a serialization format like json. It is is the deserialization that is the hard part: you have to do validation on incoming data and transform it if needed and convert it to an object. How it happened till now: serializer = ExampleSerializer(data=request.DATA, ...) serializer.is_valid() # serializer.object exists now This .is_valid() performs some validation on the serializer and it also instantiates an object. In 3.0, the validation still happens, but it only works on the serializer, not on an object. It returns validated data instead of an object. The validated data can afterwards be saved to an object explicitly. Another change is that there's a separate .create() and .update() method to split out the behaviour regarding creating new database objects or updating existing ones. The previous version determined itself whether … -
Django under the hood: django migrations - Andrew Godwin
(One of the summaries of a talk at the 2014 django under the hood conference). Andrew Godwin wrote south, the number one migrations framework for django. It is superseded by django's new built-in migrations, also written mostly by Andrew, hurray! The original idea was tho have a schema backend and hooks in the django ORM. The actual migration code would live outside of django in south2. In the end, everything is now in django. The original distinction between "schema backend stuff" and "the actual migrations" is still there in the code, however. The schema backend is relatively simple and straightforward; the migration part is hard and hairy. The migration part contains: operations, loader/graph, executor, autodetector, optimiser, state. He'll talk about some of them here. What about the old syncdb? It is a one-shot thing: you add tables and then you add the foreign keys. When migrating, you have dependencies. You cannot add foreign keys to tables you haven't added yet. There is automatic dependency-detecting code, now, but that was added quite at the last moment in the 1.7 beta 2... Basic dependencies means the obvious stuff. Some examples: Like creating a model before adding a foreign key to it. Most …