Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django 1.6 最佳实践: 最佳Django开发环境设置
在本节中, 我们将介绍最佳的本地开发环境设置 1. 在开发和部署服务器中使用相同的数据库 可能有些开发者喜欢在本地开发Django程序时, 使用SqLite3数据库, 而在部署时使用PostgreSQL数据库(或任何不同于SqLite3的数据库). 但这一做法应当避免, 因为我们是希望不同的数据库表现的一致, 这显然是不现实的. 以下是一些我们使用不同数据库进行开发和部署时遇到的问题: Fixtures不是解决方法 或许你会想, 我们为何不能用fixtures来弥补不同数据库的不同呢? 是的, fixtures能用于创建简单的手写的测试数据, 它能在开发时填充进许多假的数据, 尤其是在开发初期阶段. 但是, fixtures对于从一个数据库到另一个未知数据库的大数据迁移而言, 并不是一个可靠地工具. 它本身也不是为了这一目的而设计的, 我们不应该将创建基本数据和数据迁移的用法混淆. 无法本地测试部署后数据 当你的本地数据库和部署数据库不同时, 你无法创建一个和部署服务器完全一样的拷贝进行测试. 当然你可能会觉得使用dump将数据完全拷贝出来放到本地数据库中测试, 但是这也无法保证导出和导入后的数据是完全一样的. 不同数据库拥有不同的数据类型 请牢记, 不同的数据库处理数据的类型是不同的! Django的ORM试图统一这些不同, 但毕竟所能实现的效果是有限的. 比如, 在使用SqLite3作为测试数据库, 而使用PostgreSQL作为部署数据库时, 由于SqLite3是动态, 弱类型数据库, 而PostgreSQL则是强类型数据库, 虽然程序在测试服务器上运行正常, 但最终可能导致在部署服务器上出现问题. 2. 使用Pip和Virtualenv 如果你还没有使用Pip和Virtualenv, 那么, 我们强烈推荐你现在就开始熟悉并使用Pip和Virtualenv. Pip和Virtuaenv是Django项目的标准配置, 并且大多数开发者依赖这两个工具. Pip是从Python Package Index下载Python模块的工具, 更是管理和安装Python模块的不二选择. 它有点像easy_install, 但具有更多的功能, 其中最重要的就是对于Virtualenv的支持 Virtualenv是创建独立的Python开发环境, 管理模块依赖性的工具. 当我们同时开发多个项目时, 且这些项目使用的库或模块都有所不同时, 它可以帮助我们轻松的在这些独立开发环境质检切换. 当然为了方便使用Virtualenv, 我们可以借助virtualenvwrapper. virtualenvwrapper为我们提供了诸多命令, 方便我们使用Virtualenv 3. 使用Pip安装Django和其他依赖库 Django官网提供了多种安装Django的方式, 但我们推荐使用pip来安装Django和其他项目依赖模块. 简单而言, 每个Django项目都需要一个requirements文本文件, 其中罗列了所有本项目中使用到的Python模块, 每条信息包括了模块的名字和版本号. 我们就使用pip将这些requirements安装到项目的virtualenv中, 具体的说明我们会在将来谈到requirements时做一个详细的介绍. 4. 使用版本控制系统 版本控制系统又叫源代码管理系通, 在进行任何语言的编程时, 你都应当使用版本控制系统来管理跟踪你的源代码. 如果你不了解的话, 可以搜索一下, 应该能找到各版本控制系统的详细比较. 在所有的版本管理系统中, 我们推荐使用git. 因为第一, git似乎是现在最为流行的版本控制系统, 第二它可以方便的建立和合并分支. 在使用版本控制软件的同时, 我们推荐使用GitHub或Bitbucket作为在线的源代码仓库, 用于备份源代码仓库. 5. 试着使用Vagrant Vagrant是一个用于创建, 设置和管理开发环境的工具. Vagrant借助VirtualBox等虚拟化工具, 可以轻松的创建我们需要的虚拟机开发环境. 例如, 我们的开发环境是OS X, 而部署环境是Ubuntu时, 我们就可以使用Vagrant创建一个Ubuntu虚拟机, 并在其中配置好开发环境. 详细的介绍, 我们会在将来讲到开发环境时再谈. -
Parsing tags with django-content-bbcode in examples
Some time ago I've released django-content-bbcode - a BBCode alike tag parser. In this article I'll show some example of usage for such parser - from simple search and replace to more complex using database to get the response. -
RuntimeError: App registry isn't ready yet
The upcoming Django 1.7 has many interesting and welcomed changes. One of them is an update to how applications are loaded. The relase notes also mention potential problems with these changes. I ran into RuntimeError: App registry isn't ready yet while using the self-contained tests approach, but the fix is as simple as mentioned in the relase notes. import django django.setup() If your code needs to run on Django < 1.7 as well you could use # Django 1.7 try: import django django.setup() except AttributeError: pass Update: Dieter's comment actually made me think about my code for a second and I'll be using something different: import django if hasattr(django, 'setup'): django.setup() -
RuntimeError: App registry isn't ready yet
The upcoming Django 1.7 has many interesting and welcomed changes. One of them is an update to how applications are loaded. The relase notes also mention potential problems with these changes. I ran into RuntimeError: App registry isn't ready yet while using the self-contained tests approach, but the fix is as simple as mentioned in the relase notes. import django django.setup() If your code needs to run on Django < 1.7 as well you could use # Django 1.7 try: import django django.setup() except AttributeError: pass Update: Dieter's comment actually made me think about my code for a second and I'll be using something different: import django if hasattr(django, 'setup'): django.setup() -
RuntimeError: App registry isn't ready yet
The upcoming Django 1.7 has many interesting and welcomed changes. One of them is an update to how applications are loaded. The relase notes also mention potential problems with these changes. I ran into RuntimeError: App registry isn't ready yet while using the self-contained tests approach, but the fix is as simple as mentioned in the docs. # Django 1.7 try: import django django.setup() except AttributeError: pass -
DjangoIsland, parce que les poneys savent nager
Vous êtes djangonautes ? Et vous n’avez pas encore acheté votre billet pour DjangoCon Europe ? Alors peut-être que vous ne le saviez pas. Après tout, même si on a essayé de faire un maximum de com sur le sujet, on n’en fait jamais assez et il est fort possible que vous soyez passé à coté. Donc, je vous refais un petit topo. 3 jours de confs du 13 au 15 mai et 2 jours de sprint le 16 et 17 mai. Et tout cela en France, donc facile au niveau transport, il vous suffit de prendre un TGV. Mais surtout, surtout, ce ne sont pas trois jours de confs dans une simple salle de conf, aussi belle soit-elle. Non, ce sont trois jours de confs (et 2 jours de sprint) dans une île. Oui, dans une ILE. L’île des embiez pour être exact, une petite île qui se trouve dans le Var qui appartient à la famille Ricard. Imaginez donc la scéne. Vous sortez de votre TGV à Toulon, vous prenez un bus et vous arrivez sur un port, le port du Busc. Et la vous prenez un petit ferry et vous voguez, le doux soleil de méditerranée vous … -
NoReverseMatch at xxxx is not a registered namespace 问题解决
Django模板语言中的url命令可通过使用命名空间语法防止url名称的重复,例如: [crayon-53e8 […] -
Caktus has a new website!
It’s been a few years since we last updated our website, and we gave it a whole new look! With the new site, it’s easy to see just what services we offer, and our processes for bringing our client’s ideas to life. The new layout allows for more in-depth reviews of our projects, and also highlights our talented and growing team. We also wanted to share more information on our commitment to the open source community and social good. And the updated structure makes finding out about events and reading our ever-popular blog posts simple. The new design utilizes a responsive grid structure and a refined typographic sensibility. Wrap this all up with our new branding—adding a bold blue to our green/grey—and you get a polished and and informative new site that reflects what Caktus does best. We hope you find the new site more intuitive, user-friendly and as easy-on-the-eyes as we do! -
Caktus has a new website!
It’s been a few years since we last updated our website, and we gave it a whole new look! With the new site, it’s easy to see just what services we offer, and our processes for bringing our client’s ideas to life. The new layout allows for more in-depth reviews of our projects, and also highlights our talented and growing team. We also wanted to share more information on our commitment to the open source community and social good. And the updated structure makes finding out about events and reading our ever-popular blog posts simple. -
Django 1.7 Migrations - An Introduction
See what it takes to use the new migrations system that has been integrated into Django 1.7. This video walks you through how to create migrations, and run them. Along with a few other key points you might want to know.Watch Now... -
New for PyCon: App for Group Outings + Giant Duck
For PyCon 2014, we’ve been working for the past few months on Duckling, an app to make it easier to find and join casual group outings. Our favorite part of PyCon is meeting up with fellow Pythonistas, but without someone rounding everyone up and sorting the logistics, we’ve found it difficult to figure who’s going where and when. Our answer to this age-old conference conundrum is Duckling! -
New for PyCon: App for Group Outings + Giant Duck
For PyCon 2014, we’ve been working for the past few months on Duckling, an app to make it easier to find and join casual group outings. Our favorite part of PyCon is meeting up with fellow Pythonistas, but without someone rounding everyone up and sorting the logistics, we’ve found it difficult to figure who’s going where and when. Our answer to this age-old conference conundrum is Duckling! Duckling, made for conferences, lets you find, join, and create outings to local restaurants, bars, or other entertainment venues. You can see who’s going, when, and where they’re meeting up to leave. It’s hooked up to Yelp, so you can look at reviews before heading out. And of course, it is written in Django too! Lots of options to keep up to date on all outings at PyCon: follow @ducklingquacks, find our Duckling sign in the lobby, or come visit our booth, #700, to see a map that shows where everyone is headed. Also, our booth will have a giant duck. Why? Because look how happy it makes people! -
Comics v2.3.0 released with better mobile support
Version 2.3.0 of my comics aggregator is now released. As always, dependencies have been updated, including the routine Django upgrade from Django 1.5 to 1.6, just in time for the upcoming 1.7 release. The largest change this time around is the move from Bootstrap 2 to 3, which includes a refreshed, flatter design and lots of tweaking to make Comics both look good and work nicely on mobile devices, something it didn’t use to do. The dependency overview at requires.io has been a great motivation for doing some maintenance work on Comics. The only dependency left outdated is django-registration, as 1.0 moves to class-based views, which requires some larger changes to my customizations. Thus, the upgrade of django-registration has been deferred together with the related upgrade of my vendorized copy of django-invitation. Most, if not all, of the other dependencies seems to support Python 3 now, though some lack the right Trove classifiers in their PyPI registration, so they are not correctly labeled by requires.io. I found an open pull request for cssmin and a recent commit for django-compressor adding the missing Trove classifiers. I’ve also done my part to improve the Python 3 metadata by sending a pull request … -
Just a small announcement for today
Hi everyone. This is just a small announcement today to let everyone know that we decided to change our publication schedule. From now on we are going to try to release 2 blog posts every week, one on wednesday and one on friday. This wednesday will be the day we release Ls4c. There will be a link to the repository and documentation as well as a small tutorial on how to create a multilingual webshop using Ls4C in less than an thirthy minutes. This friday we will feature the next episode of our Django babbler tutorial series: Custom users using Django 1.6. In the mean time, have a great monday everyone! -
使用django-emoji让你的Django APP显示流行的emojis图标
gaqzi 最近的开源项目 django-emoji 可心让你的django APP 在网站上显示流行的 em […] -
App enlight - log aggregation and application health monitoring service
App enlight, a Polish startup known as errormator in the past is a application-service that logs and aggregates you application health. Like for example Sentry can log exceptions and logs (like from logging module) then App Enlight does much more by hooking to the internals of the application - you will get executed SQLs, template rendering time, slow responses and more. So let us take a closer look on current app enlight features... -
Beginner's Guide to PyCon 2014
New to Python and/or conferences and attending the upcoming PyCon 2014 in Montreal, Canada? Or is this your first conference? Or perhaps your first conference longer than a weekend? Hoping to get the most out of joining thousands of Python enthusiasts? No worries! This guide will aid you in attending one of the best technical conferences on the planet. Even though I'm not attending on account of various reasons including finances, work, and surgery, I'm going to share how to get through the whole event in good shape. I'm also going to share some great tricks to optimize the event. Basics Take at least one shower per day. Please. Bring something to take notes. A paper notebook, laptop, or tablet. Anything! If you are looking for work, bring business cards. Seriously. At every meal (breakfast, lunch, dinner) make a point of sitting with or going out with different people. Introduce yourself. Make new friends and learn new things! If you can't make it to a talk, don't stress out. They are recorded and will be available later on http://www.pyvideo.org. Act Professionally (see next section) Be Professional PyCon is a professional event. Sure, lots of people are in t-shirts and are … -
Beginner's Guide to PyCon 2015
note: This post has been updated for PyCon 2015. Even though the URL is old, the content is new. New to Python and/or conferences and attending the upcoming PyCon 2015 in Montreal, Canada? Or is this your first conference? Or perhaps your first conference longer than a weekend? Hoping to get the most out of joining thousands of Python enthusiasts? No worries! This guide will aid you in attending one of the best technical conferences on the planet. Even though I'm not attending on account of various reasons including finances, work, and personal projects, I'm going to share how to get through duration of pycon in good shape. I'm also going to share some great tricks to optimize the event. Basics Take at least one shower per day. Please. Bring something to take notes. A paper notebook, laptop, or tablet. Anything! If you are looking for work, bring business cards. Seriously. At every meal (breakfast, lunch, dinner) make a point of sitting with or going out with different people. Introduce yourself. Make new friends and learn new things! If you can't make it to a talk, don't stress out. They are recorded and will be available later on http://www.pyvideo.org. Act … -
Two Scoops of Django 1.6 India Edition Sneak Peek
We finally have a finalized proof of the forthcoming Two Scoops of Django 1.6 India Edition in our hands! The US edition, on the left, is 7.5x9.25 inches. The India edition, on the right, is sized A4, which is about 8.3x11.7 inches. The US edition is slightly thicker, but not dramatically so. The cover of the India Edition has more vibrant color (admittedly slightly rumpled thanks to the clumsy hands of the male co-author). The SD memory card and garlic clove are for scale. Printing: Our Indian printer, pothi.com, has outdone themselves. We have extremely high standards and proudly say it's a BETTER printing than the US edition. The paper feels good in the hand. The slightly increased margins make it easier to annotate. In fact, it's such an amazing book we're planning on making it available world-wide. It's just that good. We appreciate pothi.com's service and attention to detail, and hope to use them for other future projects. Content: Besides the addition of 'India Edition' in the footer, the content is identical to the US edition. Pricing: Our pricing reflects the India Edition's international distribution. While it's actually more expensive to produce than our US edition, we're going to … -
Two Scoops of Django 1.6 India Edition Sneak Peek
We finally have a finalized proof of the forthcoming Two Scoops of Django 1.6 India Edition in our hands! The US edition, on the left, is 7.5x9.25 inches. The India edition, on the right, is sized A4, which is about 8.3x11.7 inches. The US edition is slightly thicker, but not dramatically so. The cover of the India Edition has more vibrant color (admittedly slightly rumpled thanks to the clumsy hands of the male co-author). The SD memory card and garlic clove are for scale. Printing: Our Indian printer, pothi.com, has outdone themselves. We have extremely high standards and proudly say it's a BETTER printing than the US edition. The paper feels good in the hand. The slightly increased margins make it easier to annotate. In fact, it's such an amazing book we're planning on making it available world-wide. It's just that good. We appreciate pothi.com's service and attention to detail, and hope to use them for other future projects. Content: Besides the addition of 'India Edition' in the footer, the content is identical to the US edition. Pricing: Our pricing reflects the India Edition's international distribution. While it's actually more expensive to produce than our US edition, we're going to … -
Two Scoops of Django 1.6 India Edition Sneak Peek
We finally have a finalized proof of the forthcoming Two Scoops of Django 1.6 India Edition in our hands! The US edition, on the left, is 7.5x9.25 inches. The India edition, on the right, is sized A4, which is about 8.3x11.7 inches. The US edition is slightly thicker, but not dramatically so. The cover of the India Edition has more vibrant color (admittedly slightly rumpled thanks to the clumsy hands of the male co-author). The SD memory card and garlic clove are for scale. Printing: Our Indian printer, pothi.com, has outdone themselves. We have extremely high standards and proudly say it's a BETTER printing than the US edition. The paper feels good in the hand. The slightly increased margins make it easier to annotate. In fact, it's such an amazing book we're planning on making it available world-wide. It's just that good. We appreciate pothi.com's service and attention to detail, and hope to use them for other future projects. Content: Besides the addition of 'India Edition' in the footer, the content is identical to the US edition. Pricing: Our pricing reflects the India Edition's international distribution. While it's actually more expensive to produce than our US edition, we're going to … -
Approval and acceptance in the tech community
For a long time, one of my fellow core developers on the Django project has had an email signature which contains the following: "I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarising Voltaire) My perception of the reaction and noise around Brendan Eich's appointment (and subsequent resignation) as CEO of Mozilla has been that many (though by no means all) in the tech community haven't held true to this (though I think many would claim that they have). I'm afraid I can't be silent on this issue any more, and I have to speak out. You are more than welcome to disagree with me (as I'm sure many of you will!) but please at least hear me out. I was pushed further by a comment on a blog post (both of which have since disappeared) in which the author said that he would be very scared to speak out if he opposed gay marriage, and that fear is not the tactic we should be using to discourage this view. I agree completely with that sentiment. The current temperature in the programming community feels extremely hostile to … -
Two Scoops of Goblins
While Audrey Roy Greenfeld and I were contemplating our next Two Scoops Press book topic, it came down to a decision between Pyramid, Flask, and mythical creatures. Inspired by Django's magical flying pony, Pyramid's scary alien dude, and even the idea of a magical Flask pouring out wonderful projects, we've decided to go with mythical creatures. Specifically, we're writing about goblins, hence the title of this blog post. What that means is that the next book we publish will be fantasy. Going forward all the books we write will be fiction. If we ever write a new Two Scoops of Django book, it will be a fantasy about a magical flying pony who eats ice cream. That way we'll confuse the already muddled Amazon.com search requests for 'Django' even more. Since this is a technical blog, I'll be moving my fiction writing based articles to my author blog at danielroygreenfeld.com. -
Two Scoops of Goblins
While Audrey Roy Greenfeld and I were contemplating our next Two Scoops Press book topic, it came down to a decision between Pyramid, Flask, and mythical creatures. Inspired by Django's magical flying pony, Pyramid's scary alien dude, and even the idea of a magical Flask pouring out wonderful projects, we've decided to go with mythical creatures. Specifically, we're writing about goblins, hence the title of this blog post. What that means is that the next book we publish will be fantasy. Going forward all the books we write will be fiction. If we ever write a new Two Scoops of Django book, it will be a fantasy about a magical flying pony who eats ice cream. That way we'll confuse the already muddled Amazon.com search requests for 'Django' even more. Since this is a technical blog, I'll be moving my fiction writing based articles to my author blog at dannygreenfeld.com. -
Download CSV files via CSVResponseMixin
Providing csv files to people is annoying, but writing a custom mixin for use with your views can make it super easy. Often times we have to use a custom function, of some sort, and rejigger around how our views work to get a csv file, then set header information, and finally return a response. There is a Better Way Below is a custom mixin you can write, or use, to return a csv file based on a list of lists. class CSVResponseMixin(object): csv_filename = 'csvfile.csv' def get_csv_filename(self): return self.csv_filename def render_to_csv(self, data): response = HttpResponse(content_type='text/csv') cd = 'attachment; filename="{0}"'.format(self.get_csv_filename()) response['Content-Disposition'] = cd writer = csv.writer(response) for row in data: writer.writerow(row) return response The first few lines of code are simple. We are declaring the mixin, setting the filename, and returning the filename based on a method on the mixin. That leaves us with the render_to_csv method which takes a lsit of lists, and gives us a downloadable file. Line by Line Explanation response = HttpResponse(content_type='text/csv') We are creating a Django HttpResponse object which django returns, and we are setting the content type to a csv file so the browser knows what it is. response['Content-Disposition'] = 'attachment; filename="{0}"'.format(self.get_csv_filename()) We are …