Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django class-based generic views
Antes do Django 1.3, as generic views eram apenas métodos, essa versão do Django traz um novo estilo de uso, baseado em classes. Generic views foram criadas para evitar a repetição de padrões, por exemplo, sempre que você faz um formulário você terá uma ação caso o formulário seja válido, outra caso contrário. Existem muitos casos onde nos repetiremos. Um exemplo de listagem, sem o uso de uma generic view: from django.shortcuts import render def list_posts(request): posts = Posts.objects.all() render(request, 'posts/list_posts.html') Essa view é bem simples, mas poderia ser ainda mais simples com o uso de uma generic view, veja: form django.views.generic import ListView class PostLists(ListView): model = Post template_name = 'posts/posts_list.html' Se você não precisa customizar nada na sua view, pode simplesmente usar a view padrão do Django em seu urls.py: #... from django.views.generic import ListView urlpatterns = patterns('', (r'^posts/', ListView.as_view(model=Post)), ) O código anterior dispensa uma view explícita no arquivo views.py. As generic views baseadas em classe tem uma estrutura básica padrão: Todas elas herdam em sua base, da classe View e de alguns outros mixings, veja a definição da classe ListView e das classes da qual ela herda: # django/views/generic/list.py class ListView(MultipleObjectTemplateResponseMixin, BaseListView): ... class MultipleObjectTemplateResponseMixin(TemplateResponseMixin): ... … -
Google+ API and Django Authentication Backend
The Google+ developers API was released a couple of days back, I was really excited to try it out. I saw that the initial release comes with a starter project in Python for Google App Engine only. Now, when trying it out, I decided why not create a Django pluggable app for it. So, I decided to create a django app to provide a fully integrated Django style authentication backend for Google+. And thus, it comes as the newest addition to the django-custom-auths project of mine. Check the project in GitHub for details. I guess this is the first application which aims at integrating Google+ API with Django. Plese feel free to try it out. Any comments, criticism and suggestions are most welcome. Find it here: https://github.com/subhranath/django-custom-auths -
Google+ API and Django Authentication Backend
The Google+ developers API was released a couple of days back, I was really excited to try it out. I saw that the initial release comes with a starter project in Python for Google App Engine only. Now, when trying it out, I decided why not create a Django pluggable app for it. So, I decided to create a django app to provide a fully integrated Django style authentication backend for Google+. And thus, it comes as the newest addition to the django-custom-auths project of mine. Check the project in GitHub for details. I guess this is the first application which aims at integrating Google+ API with Django. Plese feel free to try it out. Any comments, criticism and suggestions are most welcome. Find it here: https://github.com/subhranath/django-custom-auths -
Stopforumspam Django Middleware
I have created a new Django app for keeping out spammers on the basis of data collected by stopforumspam.com. Read all about it here » It’s free, open source, and I hope people will make it better on github. -
Hosting Django under different locations with Nginx and gunicorn
Do you know how Django uses SCRIPT_NAME? It's not often I host different instances of Django under different locations on the same domain. One legacy install has been setup that way for over a year with Apache2 and mod_wsgi (with Nginx infront). Almost all of my new deployments use virtual hosts with different subdomains for each service. If you are using virtual hosts with Nginx it looks like this: server { listen 80; server_name service.albertoconnor.ca; # other settings location / { try_files $uri/index.html $uri.html $uri @cluster; } location @cluster { proxy_pass http://service.albertoconnor.ca; } } Assuming you have defined an upstream server cluster called "service.albertoconnor.ca". If you are doing something by location on the same domain it might look something more like this: server { listen 80; server_name _; # other settings... location /a/ { proxy_pass http://127.0.0.1:8001/; } location / { proxy_pass http://127.0.0.1:8080/; proxy_redirect off; } } The idea is that something else, let's say Apache2, is running on 127.0.0.1:8080, and Django being served by gunicorn is running on 127.0.0.1:8001. So under /a/ the pages will be generated by Django; anywhere else Apache2 takes over. If you try this though, things will go horribly wrong. Besides redirects not working because you … -
Hosting Django under different locations with Nginx and gunicorn
Do you know how Django uses SCRIPT_NAME? It's not often I host different instances of Django under different locations on the same domain. One legacy install has been setup that way for over a year with Apache2 and mod_wsgi (with Nginx infront). Almost all of my new deployments use virtual hosts with different subdomains for each service. If you are using virtual hosts with Nginx it looks like this: server { listen 80; server_name service.albertoconnor.ca; # other settings location / { try_files $uri/index.html $uri.html $uri @cluster; } location @cluster { proxy_pass http://service.albertoconnor.ca; } } Assuming you have defined an upstream server cluster called "service.albertoconnor.ca". If you are doing something by location on the same domain it might look something more like this: server { listen 80; server_name _; # other settings... location /a/ { proxy_pass http://127.0.0.1:8001/; } location / { proxy_pass http://127.0.0.1:8080/; proxy_redirect off; } } The idea is that something else, let's say Apache2, is running on 127.0.0.1:8080, and Django being served by gunicorn is running on 127.0.0.1:8001. So under /a/ the pages will be generated by Django; anywhere else Apache2 takes over. If you try this though, things will go horribly wrong. Besides redirects not working because you … -
Working with the Django admin and legacy databases, pt.3
Working with the Django admin and legacy databases, pt.3 -
Working with the Django admin and legacy databases, pt.2
Working with the Django admin and legacy databases, pt.2 -
Contributing to Django Documentation, Part 1: Generating and Editing Documentation Locally
Contributing to Django Documentation, Part 1: Generating and Editing Documentation Locally -
Image resizing on file uploads. Doing it the easy way.
Image resizing on file uploads. Doing it the easy way. -
Contributing to Django Documentation, Part 2: Submitting A Patch
Contributing to Django Documentation, Part 2: Submitting A Patch -
DjangoCon 2011 Wrap Up
Sadly DjangoCon 2011 has come and gone and while I’m sad that it is over I’m excited to try the things I learned over the conference. There were a number of excellent talks by a number of great speakers but there were a few that stood out to me. Advanced Security Topics – Paul McMillan had a great talk on different security aspects of Django. He showed a couple of critical flaws (that were patched in 1.3.1 and 1.2.7. He also talked about the django-secure application that can help you plug your security holes within your own Django projects. Overall this was my favourite talk due to Paul’s excellent presentation and the quality of the content. Secrets of PostgreSQL Performance – Frank Wiles also had a great talk on performance tuning your PostgreSQL server. While this wasn’t really geared towards Django I thought there were a number of great performance tips that he gave to speed up your DB server. I’ve already followed a few of these tips and have noticed a slight increase in performance. The Story and Tech of Read The Docs – Eric Holscher talked about how Read The Docs came to be and the technology of … -
Quick conferences report: Presentations
My lovely Fiancée, Audrey Roy, was invited to be the opening keynote speaker at both PyCon Australia on Diversity in Python (video) and PyCon New Zealand on Python on the Web.As for me, I managed to get talks into both of those conferences AND DjangoCon US. I co-presented on three of them, and I share all credit for success with my cohorts. The talks I gave at the conferences were (I'll post videos when they get up):Confessions of Joe Developer (PyCon Australia, DjangoCon US)The genesis of this talk was as a lightning talk at I gave at the Hollywood Hackathon. It is a talk about admitting that us mere mortals need to ask questions, take notes, and follow good practices in general. I gave it again at LA Django this summer, extending it to a full length talk complete with lots of technical content. At PyCon Australia I toned down the technical content because I was nervous, and while the response was positive, it could have been much better. So for DjangoCon I ramped up the tech-talk and it worked much better. I've now given the talk 4 times, and I'm leaning towards retiring it. Python Worst Practices (PyCon New Zealand)This talk grew out … -
Try Redis instead
Redis is an invaluable part of software on my server. If you have never tried, or seen it, you should go and install it anyway. You can benefit from Redis just by changing a couple of Django settings. Furthermore, it can replace several uselessly humongous applications you are probably considering right now. -
Testing Web Server Configurations with Fabric and ApacheBench
Load testing a site with ApacheBench is fairly straight forward. Typically you'd just SSH to a machine on the same network as the one you want to test, and run a command like this:ab -n 500 -c 50 http://my.web.server/path/to/page/ The -n argument determines the number of requests to execute, and the -c argument the determines ... -
Testing Web Server Configurations with Fabric and ApacheBench
Load testing a site with ApacheBench is fairly straight forward. Typically you'd just SSH to a machine on the same network as the one you want to test, and run a command like this: -
Contributing to Django Documentation, Part 2: Submitting A Patch
Contributing to Django Documentation, Part 2: Submitting A Patch -
Contributing to Django Documentation, Part 1: Generating and Editing Documentation Locally
Contributing to Django Documentation, Part 1: Generating and Editing Documentation Locally -
Gedit as a Django IDE for Linux
gedit is actually a pretty bad ass IDE for Django web development. -
Por: Marcos Alcazar
gracias! -
Por: jjconti
La verdad no la uso hace rato. -
Por: Marcos Alcazar
juanjo, seguis usando esta app? en code.google desde mediados de 2010 que no hay commits, y encontré en github una que parece ser la misma :S https://github.com/mirumee/dja…… alguna idea o recomendación? -
How to discover unit tests from your project
Within code snippet below implemented very primitive way to collect your unit tests within your project. This is not for real project - I know at least two of fancy discovering tools - it's nose and discover , which do same thing in more convenient and accurate way.I was curious and I did it.# -*- coding: utf-8 -*-import osimport sysimport unittestFILE_ABSPATH = lambda p: os.path.dirname(os.path.abspath(p))COMPARE_DIRS = lambda a, b: FILE_ABSPATH(a) == FILE_ABSPATH(b)def collect_tests(): """ Function to collect tests from whole project """ basedir = os.path.abspath(os.path.dirname(__file__)) main_module = os.path.basename(basedir) test_file = "tests.py" test_dir = "tests" tests = [] new_locals = {} for root, dirs, files in os.walk(basedir): if test_file in files and \ os.path.join(root, test_file) != os.path.abspath(__file__): tests.append(os.path.join(root, test_file)) if os.path.dirname(root) == test_dir: tests.append(root) for test in tests: test_path = test.replace(basedir, '').replace('.py', '') module_name = "%s%s" % (main_module, test_path.replace('/', '.')) __import__(module_name) module = sys.modules[module_name] for cls in dir(module): attr = getattr(module, cls) try: attr.__module__ except AttributeError: continue # we don't want to import anything from current file if COMPARE_DIRS(sys.modules[attr.__module__].__file__, __file__): continue try: if issubclass(attr, unittest.TestCase): new_locals[cls] = attr except TypeError: pass return new_locals# execute testsif __name__ == '__main__': locals().update(collect_tests()) unittest.main() -
Django South : How To Fix The UnknownMigration Exception Error
Django South : How To Fix The UnknownMigration Exception Error -
Language redirects for multilingual sites with Django CMS …
If you have a multilingual website that uses Django CMS probably you have noticed that your pages can be opened both with and without language code in the URL? This leads to duplicate content but this is easy to fix problem.