background preloader

Django REST framework

Django App Engine Djangoappengine contains all App Engine backends for Django-nonrel, e.g. the database and email backends. In addition we provide a testapp which contains minimal settings for running Django-nonrel on App Engine. Use it as a starting point if you want to use App Engine as your database for Django-nonrel. We've also published some details in the Django on App Engine blog post. Installation Make sure you've installed the App Engine SDK. Clone the following (on those pages you can also download a zip file): If you downloaded zip files then now's the time to unzip everything. Copy the following folders into your project (e.g., django-testapp): django-nonrel/django =><project>/djangodjangotoolbox/djangotoolbox =><project>/djangotoolboxdjango-autoload/autoload =><project>/autoloaddjango-dbindexer/dbindexer =><project>/dbindexerdjangoappengine =><project>/djangoappengine That's it. <project>/django<project>/djangotoolbox<project>/autoload<project>/dbindexer<project>/djangoappengine Field types Other

Python Multithreaded Programming Running several threads is similar to running several different programs concurrently, but with the following benefits − Multiple threads within a process share the same data space with the main thread and can therefore share information or communicate with each other more easily than if they were separate processes.Threads sometimes called light-weight processes and they do not require much memory overhead; they care cheaper than processes. A thread has a beginning, an execution sequence, and a conclusion. It has an instruction pointer that keeps track of where within its context it is currently running. It can be pre-empted (interrupted)It can temporarily be put on hold (also known as sleeping) while other threads are running - this is called yielding. Starting a New Thread To spawn another thread, you need to call following method available in thread module: thread.start_new_thread ( function, args[, kwargs] ) Example #! When the above code is executed, it produces the following result − #! #!

A JavaScript and Web Design/Programming Resource By Matt Snider | Coverage and Mock This article continues the series on building a continuous deployment environment using Python and Django. So far we have covered the basics of setting up a Django project and testing it. Today we will discuss how to ensure your tests fully cover the application using the Python mock and coverage tools. Getting ready Coverage is a tool that indicates the lines of code executed when a command runs, such as manage.py test. Mock is a tool that allows developers to specify fake responses for parts of their code. How to do it… Coverage Using coverage is really easy, simply run the test management command through it: You may also output the report in HTML or XML formats: Using coverage this way works, as long as you ensure each file in the project is imported by the tests, because coverage will only report on files that are loaded during the run command. Fortunately, there is a Django coverage tool (version 1.2 was the latest when writing this article): Using Mock Mock - Mocking and Testing Library

Voando com o Django no Google App Engine | Francisco Souza O Google App Engine é uma ferramenta sensacional para desenvolvedores web. Uma ferramente certamente útil e que deveria pelo menos ser experimentada por todo desenvolvedor web que se preza :) A primeira linguagem de programação suportada pelo App Engine foi o Python, e hoje a linguagem Java também é suportada. Python é uma linguagem com muitos frameworks web (muitos mesmo), e você pode usar alguns deles no App Engine. Resolvi, então, criar uma série com três posts sobre como usar três frameworks web Python no Google App Engine: Django, Flask e web2py. Em todos os casos, desenvolverei uma aplicação simples, que será enviada para o Google App Engine e disponibilizada publicamente :) Nesta primeira parte, abordarei o Django, o mais famoso dentre os frameworks Python para a web. O principal recurso do Django é a camada de modelo, chamada Django models. O primeiro passo é deixar o ambiente pronto para receber nosso código (e voar em produção =P). default_expiration: ‘365d’ $ . $ . )[/cc] $ . $ .

How to Get Started with PAnt Follow these steps to to get started with PAnt: Download Jython. Note that as of right now Jython 2.5 is somewhat slower to initialize than 2.2. You only need 2.5 if you want to be able to use decorators to create Ant targets. Now the prep work is done and you can begin developing your build logic in python. That's it, the rest of it is simply writing your build logic in python using Ant tasks as documented here. Django Performance Patterns 1: Measuring Performance Preface As Django has matured it’s being used for bigger and bigger projects. At the same time it’s also being used by more and more people building relatively simple applications quickly. Everyone’s application is different, but I’d wager the vast majority of these have a range of common performance problems. Performance is often something only larger teams get to spend time really getting to grips with. One advantage of using a framework is the sharing of common solutions to common problems that happens as a community forms. I’m going to be pretty opinionated about the stack I’m using when necessary. Measuring Performance In this first part of the series lets take a quick detour to frame everything else. We’ll start out looking at a few tools which are useful when taking a view by view approach to analysing performance. Django Debug Toolbar Most Django developers will hopefully already be using the excellent Debug Toolbar. It’s very simple to install: pip install django-debug-toolbar

Build a simple GIS web application using GeoDjango and Google Maps — Tutorials v0.9.0 documentation By the end of this tutorial you will have built a simple GIS web application for viewing, editing, searching and uploading GIS data. We first presented this tutorial as part of a three-hour session on Working with Geographic Information Systems in Python during the 2009 Python Conference in Chicago, Illinois. This tutorial has been updated to work with Django 1.3. Example Make sure that the latest version of GeoDjango is installed; see Install GeoDjango. Start PostgreSQL server. su -c 'service postgresql start' Create PostgreSQL user and PostGIS database. createuser -U postgres geouser -S -D -R psql -U postgres -c "alter role geouser with password 'geopassword';" createdb -U postgres -T template_postgis -O geouser geodatabase Download the code and data. wget unzip geodjango-googlemaps.zip cd geodjango-googlemaps/googlemaps Setup tables. Run server. python manage.py runserver Walkthrough Create spatial database Configure settings

Repository Structure and Python This opinionated guide was written for my best-practices guide, The Hitchhiker’s Guide to Python. It is based on the recommendations of the Distribute project, personal experience, and good intentions. It’s Important. Just as Code Style, API Design, and Automation are essential for a healthy development cycle, Repository structure is a crucial part of your project’s architecture. When a potential user or contributor lands on your repository’s page, they see a few things: Project NameProject DescriptionBunch O’ Files Only when they scroll below the fold will the user see your project’s README. If your repo is a massive dump of files or a nested mess of directories, they might look elsewhere before even reading your beautiful documentation. Dress for the job you want, not the job you have. Of course, first impressions aren’t everything. Sample Repository tl;dr: This is what I recommend. This repository is available on GitHub. Let’s get into some specifics. The Actual Module Location . . . License . How?

Re-ordering child nodes in django-MPTT Integrating Django with Nose at DISQUS by David Cramer About a month ago we decided to make the transition off of Django’s test suite over to the Nose runners. Our main selling point was the extensibility, and the existing ecosystem of plugins. Four weeks later I’m happy to say we’re running (basically) Nose with some minor extensions, and it’s working great. Getting Django running on Nose is no small feat. Luckily, someone else has already put in a lot of that effort, and packaged it up all nice and neat as django-nose. I won’t go through setting up the package, but it’s pretty straight forward. A few of the big highlights for us: Xunit integration (XML output of test results) Skipped and deprecated test hooks The ability to organize tests outside of the Django standards I’m wanted to talk a bit about how we solved some of our problems, and the other benefits we’ve seen since adopting it. Test Organization The biggest win for us was definitely being able to reorganize our test suite. Unittest Compatibility Test Case Selection Bisecting Tests

PyPy :: PyPy Beating Google With CouchDB, Celery and Whoosh (Part 3) « Andrew Wilkinson In this series I’ll show you how to build a search engine using standard Python tools like Django, Whoosh and CouchDB. In this post we’ll start crawling the web and filling our database with the contents of pages. One of the rules we set down was to not request a page too often. If, by accident, we try to retrieve a page more than once a week then don’t want that request to actually make it to the internet. We only actually want to retrieve the page from the internet in one of the three tasks the we’re going to create so we’ll give get_by_url a parameter, update that enables us to return None if we don’t have a copy of the page. The key line in the static method is doc.update(). We need to split up the given URL so we know whether it’s a secure connection or not, and we need to limit our connects to each domain so we need get that as well. In the previous post we discussed parsing the robots.txt file and here we make sure that if we’re not allowed to index a page, then we don’t Like this:

The environment dictionary, env — Fabric 1.5.1 documentation A simple but integral aspect of Fabric is what is known as the “environment”: a Python dictionary subclass, which is used as a combination settings registry and shared inter-task data namespace. The environment dict is currently implemented as a global singleton, fabric.state.env, and is included in fabric.api for convenience. Keys in env are sometimes referred to as “env variables”. Below is a list of all predefined (or defined by Fabric itself during execution) environment variables. Note that many of these may be set via fab‘s command-line switches – see fab options and arguments for details. abort_exception Default: None Fabric normally handles aborting by printing an error message to stderr and calling sys.exit(1). Give it a callable which takes a string (the error message that would have been printed) and returns an exception instance. abort_on_prompts Default: False all_hosts Default: [] Set by fab to the full host list for the currently executing command. always_use_pty Default: True cwd

Related: