Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Release 1.1.1
-
Django 1.6 最佳实践: Continuous Integration
Continuous integration (CI) 是一种软件开发实践, 常用于团队间频繁合并工作使用. 每一次合并都要经过自动构建和测试尽快验证其正确性. 许多团队都发现这一方式能大大降低合并中出现的麻烦和, 并增强软件统一性. 以下是一个典型的开发流程: 程序员写代码, 运行本地测试, 将代码推至代码库, 通常最少一天一次 代码库变化触发自动构建工具 自动构建工具运行构建程序. 其间发生任何错误就将本次推送驳回 自动构建工具运行测试程序. 其间发生任何错误就将本次推送驳回 自动构建工具将结果通知开发人员 这一过程有以下优势: 能以最快速度发现bug 便于发现其他问题 每天合并代码的结果导致不会有一次性大规模的改变代码的情况发生 利于对项目的反馈 减轻许多麻烦的事物 1. Continuous Integration 的原则 接下来, 我们讨论一下Continuous Integration的原则: 大量测试 Continuous Integration的前提是构写大量的测试代码. 没有完整的测试就无法做到Continuous Integration. 有些人可能会不同意, 觉得没有测试, 照样可以完成Continuous Integration, 而且也能带给团队同样的优势: 测试开发过程是否成功, 将每个人的代码都同步. 但这一情况是建立在编译语言上的, 因为编译语言在编译时就保障了代码的正确性(不包括其功能性). 保持快速构建 随着开发时间的进行, 测试可能会变得越来越慢, 为此我们提供了一下技巧: 避免使用fixture 没有必要时便面使用TransactionTestCae 避免构写大量setUp()代码 构写小而专一的测试代码 学习数据库优化 2. Continuous Integration 的工具 可以使用以下工具: Tox Tox是一个virtualenv管理和测试用命令行工具, 可以帮助我们使用一个简单的命令对多个Python和Django版本进行测试. 对于不同的数据库, 也应当进行测试. 这是全世界的程序员测试不同版本python兼容性的通用工具. Jenkins Jenkins是一个Continuous Integration的引擎, 也是一个Continuous Integration的标准. 也有许多在线工具继承了Jenkins供我们方便的使用, 有些更是可以方便的集成到类似GitHub, BitBucket等的代码管理库中, 例如Travis-CI, CircleCI和Drone.io. -
Ansible thoughts (plus questions for which I need your input)
Now... how do we structure our servers? How do we put our software on them? How do we configure them? I've done my share of server maintenance and devops and what have you. On linux, that is. Maintaining my own (web)server since 1996 or so. Done a lot with buildout (which means grabbing everything together for a site that has to do with python). Automated much of our installation with Fabric so that $ bin/fab update production was more or less the standard way to update a site. So I know my way around reasonably and I normally keep everything pretty neat and tidy. Now Ansible has come along and several of our sites are managed with that tool. It feels like a much more elaborate version of Fabric. "Elaborate" is meant very positively here. And I want to dive into it and start using it too. Fabric is great for executing commands via ssh on a remote server (including copying files, modifying files etc). Ansible also executes commands via ssh, but comes with a complete system for storing your configuration, handling variables, dividing up the workload into libraries and also for sharing those libraries (called "roles" in ansible-speak). Problem … -
Adding CKEditor to your Django Admin
How much hard work are those standard textareas in your Django Admin? Lets change that by adding a full HTML text editor…. ckeditor, anyone? Yeah, I know, there are a lot of packages that already do this. However, if all you require is a simple WYSIWYG editor within your admin, it's so easy and far more elegant to just add one in yourself. In jut 3 steps: 1) Download the latest version of CKEditor. 2) Place all the CKEditor files you just downloaded into your static root so it can be served. 3) In your admin.py add something like the following... from django.contrib import admin from django.db import models from django import forms from .models import Entry class EntryAdmin(admin.ModelAdmin): formfield_overrides = { models.TextField: {'widget': forms.Textarea(attrs={'class':'ckeditor'})}, } list_display = ['title', 'creation_date', 'status'] class Media: js = ('ckeditor/ckeditor.js',) admin.site.register(Entry, EntryAdmin) Done! You now have an HTML text editor on your textarea. So what did we just do? All that’s happened is we told Django to replace any textareas with the ckeditor code. When ckeditor starts up it knows to replace any textareas with the ckeditor code becuase we added the class=ckeditor to them. The Class Media will add the required … -
My Blog Search: Haystack and Whoosh
The observant of you may have noticed I finally have search functionality on my blog, yeah!!! After doing a bit of research I decided that SOLR would be far too ambiguous for my simple requirements. With this considered I decided to implement Haystack utilising the Whoosh engine for the search backend. If you don’t know, Whoosh is a pure Python search backend, which means familiarity, perfect! Here is a quick example of how I set this up. First I installed Whoosh and Haystack using pip. sudo pip install Whoosh sudo pip install django-haystack Then in my settings.py I added the haystack application. INSTALLED_APPS = [ # Added. 'haystack', 'blog', ] Next, my settings.py I then needed to tell Haystack what backend I’m using. # Search Haystack import os HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), }, } At the same level as my setings.py I created a new file called 'search_sites.py' and added the following to it. import haystack haystack.autodiscover() This will cause haystack to look for any search_indexes.py files inside each app in my project site. I needed the appropriate URL's of course. (r'^search/', include('haystack.urls')), Now the configuration is out of the way, Haystack needed to … -
Project: Maintenance Mode App - django-time-out
Time out: A reusable Django application that that allows you to put your Django site into maintenance mode. This application simply runs middleware that checks to see if the site is down for maintenance based on scheduled maintenance dates/times added to the DB. Check it out. Installation To get the latest stable release from PyPi pip install django-time-out To get the latest commit from GitHub pip install -e git+git://git.com:sparky300/django-time-out.git#egg=time_out Add time_out to your INSTALLED_APPS NSTALLED_APPS = ( ..., 'time_out', ) Add down_time middleware class to your settings. 'time_out.middleware.DownTimeMiddleware', Don't forget to migrate your database ./manage.py migrate time_out Don't forget to migrate your database ./manage.py migrate time_out Contribute If you want to contribute to this project, please perform the following steps. # Fork this repository # Clone your fork $ mkvirtualenv -p python2.7 django-time-out $ python setup.py install $ pip install -r dev_requirements.txt $ git co -b feature_branch master # Implement your feature and tests $ git add . && git commit $ git push -u origin feature_branch # Send us a pull request for your feature branch -
Project: SagePay payment gateway package for django-oscar
SagePay payment gateway package for django-oscar provides a direct integration that enables you to collect your customers’ payment information on your own secure servers and securely pass card details across to SagePay. This means that you can completely tailor the payment process to suit your business requirements. Documentation Visit Pypi -
Installing Python and Django on Windows
For my own reference I just wanted to document my first time installing Python and Django on Windows 8.  I have installed Python before on a Mac, but never on Windows. To begin with I installed the Python 2.7 (the version Django is compatible with at this point in time). First, I downloaded and installed Python. Python has an ‘installer’ so this was straightforward. I would recommend the install location to be short and simple c:/python27. It's a lot easier on your command prompt typing later on. Python is not added to the DOS path by default. I needed to tell windows the PATH environment variable to include paths to Python executable and additional scripts.  Under My Computer > Properties > Advanced System Settings > Environment Variables > I created a new variable called "PythonPath” and added the following… C:\Python27\;C:\Python27\Scripts; Above being my location to the Python executable. Now that I had Python installed, it was time to install Django. I download the Django files then opened the command prompt. Using the Command Prompt I changed directory (“cd”) into the extracted Django directory. I then typed the following... python setup.py install This installs Django into Python’s site-packages directory. The download … -
Resetting migration history Django South
Just something useful when it comes to resetting migration history using Django South. rm -r appname/migrations/ ./manage.py reset south ./manage.py convert_to_south appname I had to do this recently and I was somewhat apprehensive at first. No need to be tho. I just opened up terminal removed the migration folder from the app , used the reset command and then converted the app just like it was an existing one. Doing this does mean that South assumes your database is identical to the app models.py. -
Fix: vertualenv EnvironmentError: mysql_config not found
Have you ever had what should be a simple task just drive you insane? For me, it's setting up a new Django project using virtualenv on my home Mac running 10.8! For some reason this Mac likes to misbehave! I get the same error every time I try to install MySQL-python within virtualenv vertualenv EnvironmentError: mysql_config not found I cannot take any credit for this fix, after many searches I found the solution here. It's a simple fix just to edit the /bin/activate file from the virtualenv directory and add the following lines, _OLD_VIRTUAL_PATH="$PATH" PATH="$VIRTUAL_ENV/bin:$PATH" PATH="$PATH:/usr/local/mysql/bin/" export PATH That's it, just make sure you match your paths to your own configuration. Now MySQL-python installs under virtualenv as normal. -
Django 1.5 deployment on Amazon EC2 Ubuntu
Introduction Six months ago I began my Django journey. Since then I have setup, installed and utilised many different deployment mechanisms for projects. This tutorial demonstrates the installation and deployment solution I found to be the most fitting for my own Django projects. So, I’d like to share… Why Git? I’ve been using Git for deployment within our company for sometime. It was a natural fit since all our projects already used GIT for version control and our development team understands it. What’s best, it's completely free! Prerequisites One will assume you are already familiar, perhaps even using GIT and have a basic understanding of Apache, Ubuntu Server and Django. I tend to use Cloud computing such as Amazon AWS. I have tested this tutorial on a EC2 instance running Ubuntu 12. Installing our Server Software So as mentioned above I’ll be using an EC2 instance for this writeup. So first ssh in and do any updates. apt-get update apt-get upgrade Next, you will need to install Apache2, Python, and PIP using the following commands... apt-get -y install apache2-mpm-worker apache2-dev apt-get -y install python python-dev python-setuptools sudo apt-get install python-pip pip install --upgrade pip We will wget the latest mod_wsgi, … -
Adding CKEditor to your Django Admin
How much hard work are those standard textareas in your Django Admin? Lets change that by adding a full HTML text editor…. ckeditor, anyone? Yeah, I know, there are a lot of packages that already do this. However, if all you require is a simple WYSIWYG editor within your admin, it's so easy and far more elegant to just add one in yourself. In jut 3 steps: 1) Download the latest version of CKEditor. 2) Place all the CKEditor files you just downloaded into your static root so it can be served. 3) In your admin.py add something like the following... from django.contrib import admin from django.db import models from django import forms from .models import Entry class EntryAdmin(admin.ModelAdmin): formfield_overrides = { models.TextField: {'widget': forms.Textarea(attrs={'class':'ckeditor'})}, } list_display = ['title', 'creation_date', 'status'] class Media: js = ('ckeditor/ckeditor.js',) admin.site.register(Entry, EntryAdmin) Done! You now have an HTML text editor on your textarea. So what did we just do? All that’s happened is we told Django to replace any textareas with the ckeditor code. When ckeditor starts up it knows to replace any textareas with the ckeditor code becuase we added the class=ckeditor to them. The Class Media will add the required … -
My Blog Search: Haystack and Whoosh
The observant of you may have noticed I finally have search functionality on my blog, yeah!!! After doing a bit of research I decided that SOLR would be far too ambiguous for my simple requirements. With this considered I decided to implement Haystack utilising the Whoosh engine for the search backend. If you don’t know, Whoosh is a pure Python search backend, which means familiarity, perfect! Here is a quick example of how I set this up. First I installed Whoosh and Haystack using pip. sudo pip install Whoosh sudo pip install django-haystack Then in my settings.py I added the haystack application. INSTALLED_APPS = [ # Added. 'haystack', 'blog', ] Next, my settings.py I then needed to tell Haystack what backend I’m using. # Search Haystack import os HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), }, } At the same level as my setings.py I created a new file called 'search_sites.py' and added the following to it. import haystack haystack.autodiscover() This will cause haystack to look for any search_indexes.py files inside each app in my project site. I needed the appropriate URL's of course. (r'^search/', include('haystack.urls')), Now the configuration is out of the way, Haystack needed to … -
Project: Maintenance Mode App - django-time-out
Time out: A reusable Django application that that allows you to put your Django site into maintenance mode. This application simply runs middleware that checks to see if the site is down for maintenance based on scheduled maintenance dates/times added to the DB. Check it out. Installation To get the latest stable release from PyPi pip install django-time-out To get the latest commit from GitHub pip install -e git+git://git.com:sparky300/django-time-out.git#egg=time_out Add time_out to your INSTALLED_APPS NSTALLED_APPS = ( ..., 'time_out', ) Add down_time middleware class to your settings. 'time_out.middleware.DownTimeMiddleware', Don't forget to migrate your database ./manage.py migrate time_out Don't forget to migrate your database ./manage.py migrate time_out Contribute If you want to contribute to this project, please perform the following steps. # Fork this repository # Clone your fork $ mkvirtualenv -p python2.7 django-time-out $ python setup.py install $ pip install -r dev_requirements.txt $ git co -b feature_branch master # Implement your feature and tests $ git add . && git commit $ git push -u origin feature_branch # Send us a pull request for your feature branch -
Project: dajngo-stencil
dajngo-stencil is a a boilerplate project for starting development based on my own setup. I start my projects in the same way and django-stencil is a way for me to jump start it. If you would like to give it a go run the following command: $ django-admin.py startproject --template=https://github.com/sparky300/django-stencil/zipball/master project_name Where project_name is the name of the project you'd like to create. -
Project: SagePay payment gateway package for django-oscar
SagePay payment gateway package for django-oscar provides a direct integration that enables you to collect your customers’ payment information on your own secure servers and securely pass card details across to SagePay. This means that you can completely tailor the payment process to suit your business requirements. Documentation Visit Pypi -
Tutorial: Using AngularJS with Django
I’m hoping to write a quick tutorial to get you started using Angular with Django What it turned into was a tutorial fueled by Red Bull. My apologies if it gets sloppy towards the end! Having read posts on the subject of using Django and Angular together, I felt most were reinventing the wheel, so to speak. Although the example code I have given is crude it should highlight how I've been using them on projects. Models Lets start with a typical Model. /jobs/models.py class Job(models.Model): name = models.CharField(max_length=50) description = models.TextField(null=True, blank=True) Alright, nothing special so far. All you have done is create a simple model to contain basic job details. The REST API (Tastypie) AngularJS is built to consume webservices, so your gonna need a way to expose the Job Model you just created. Django has a good set of choices to create RESTful APIs. TastyPie is an awesome webservice framework built for the Django framework. It's incredibly powerful, yet easy to setup and use. However, personal preference aside, the same results could be achieved using Django REST framework, or even constructing your own API responses directly using Django. The choice is entirely yours. For the purposes of this tutorial we'll be using TastyPie. If you're not … -
Django 1.6 最佳实践: 如何确保相同的开发环境
如何保证各个程序员之间的开发环境相同是个复杂的问题, 我们可能存在以下问题: 1.操作系统不同, 2.python配置不同. 有的程序员用的是windows, 也有使用mac和Linux的, 有些程序员甚至不知道自己使用的是哪个版本的python. 每次换了新的硬件, 都需要重新安装和设置相同的操作系统, 这样十分麻烦, 以下是当前可有的解决这一问题的选项: 在虚拟机中开发: 以前这一选择是无法想象的, 因为虚拟机设置复杂, 速度又慢. 但现在却不同了, 使用Vagrant配合虚拟机, 这一选择变得十分方便. 在Docker管理的LxC容器中开发: 类似于在虚拟机中开发, 但更轻量级. LxC容器可以共享host主机的硬件资源, 使其效率更高. 1. Vagrant Vagrant是VirtualBox或其他虚拟机的一个wrapper, 它可以让你使用一个命令行就配置好你想要的VM(虚拟机). 通过Vagrant创建的VM可以使用命令行访问和控制, 免去了GUI的繁琐. Vagrant的优势是, 其创建的VM可以通过scripts, Salt, Ansible, Chef或Puppet管理, 使得我们可以在不同的环境中设置相同的开发环境. Vagrant可能的劣势则是, 自动化的配置可能会降低我们队底层架构的理解, 在较老的电脑上, 虚拟机可能运行较慢. 2. Docker Docker是一个允许我们轻松创建Linux container(LxC)的开源项目. 这与许多PaaS使用的部署环境类似. Docker的优势是使用host资源, 因此部署十分迅速. 但需要注意的是, Docker正在开发中, 处于测试阶段可能还不能用于正式服务器上. -
PUT and DELETE HTTP requests with Django and jQuery
Sometimes it could be useful and elegant to have a Django view responding to more that GET and POST requests, implementing a simple REST interface. In this post I’ll show how you can support PUT and DELETE HTTP requests in Django. Table of Contents Your goal The problems The solution What about the function based views? Conclusion Your goal To put it in examples your goal is to have a View like this: from django.views.generic import View from django.shortcuts import redirect, render from django.forms.models import modelform_factory from django.http import HttpResponse from .models import MyModel class RestView(View): def get(self, request): # retrieve some object and render in template object = MyModel.objects.get(pk=request.GET['pk']) return render(request, 'object_detail.html', {'object': object}) def put(self, request): # create an object and redirect to detail page modelform = modelform_factory(MyModel) form = modelform(request.PUT) if form.is_valid(): form.save() return redirect('restview') def delete(self, request): # delete an object and send a confirmation response MyModel.objects.get(pk=request.DELETE['pk']).delete() return HttpResponse() And accessing the view by jQuery Ajax methods like this: $.ajax({ type: 'DELETE', url: '/restview', data: { pk: pk }, success: function() { alert('Object deleted!') } }); The problems Unfortunately there are two problems that restrict you to implement the view and the javascript like described above: … -
Links
There is a new version of gunicorn, 19.0 which has a couple of significant changes, including some interesting workers (gthread and gaiohttp) and actually responding to signals properly, which will make it work with Heroku. The HTTP RFC, 2616, is now officially obsolete. It has been replaced by a bunch of RFCs from 7230 to 7235, covering different parts of the specification. The new RFCs look loads better, and it’s worth having a look through them to get familiar with them. Some kind person has produced a recommended set of SSL directives for common webservers, which provide an A+ on the SSL Labs test, while still supporting older IEs. We’ve struggled to find a decent config for SSL that provides broad browser support, whilst also having the best levels of encryption, so this is very useful. A few people are still struggling with Git. There are lots of git tutorials around the Internet, but this one from Git Tower looks like it might be the best for the complete beginner. You know it’s for noobs, of course, because they make a client for the Mac I haven’t seen a lot of noise about this, but the EU has outlawed pre-ticked … -
django-chile-payments
If you have ever implemented support for a payment broker in your project there's a chance that you have come across brokers that are a delight to use and implement. And others that are, frankly, a pain in the ass to work with. Here in Chile, the only choice you have (as we are writing this post in June 2014) if you want to process payments through credit or debit cards is Webpay Plus from Transbank. There are certainly some other services wrapping Transbank platform to offer a more user-friendly, but they charge higher rates as they become a re-seller. Also you could implement solutions such as Paypal and operate with dollars, but although it has become recently easier for businesses to transfer Paypal funds to chilean pesos, it is not likely that most of your chilean customers will have Paypal accounts ready with dollars to spend. Things would not be so terrible if Transbank API was something enjoyable to implement as Stripe or similar. Dream on. Documentation is frequently outdated or incomplete, their list of requirements to fulfill is tough, and they force you to set up your stack with legacy technologies (e.g. you must run CGI scripts) and … -
Heroku Django S3 for serving Media files
Why should i store my media files on AWS S3? Heroku dynos have limited life span, and when they die and get replaced, the files within them are lost. So you should set up Django media handler to put the files somewhere permanent. Let's begin: 1) Install dependencies: $ pip install django-storages boto (Update your requirements.txt using pip freeze > requirements.txt) 2) Update INSTALLED_APPS in your settings.py: INSTALLED_APPS += ('storages',) 3) Sign in to AWS Console, select S3 under Storage & Content Delivery and create a bucket. 4) Don't forget to generate AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. 5) Add the below to your settings file: AWS_QUERYSTRING_AUTH = False AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID'] AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY'] AWS_STORAGE_BUCKET_NAME = os.environ['S3_BUCKET_NAME'] MEDIA_URL = 'http://%s.s3.amazonaws.com/your-folder/' % AWS_STORAGE_BUCKET_NAME DEFAULT_FILE_STORAGE = "storages.backends.s3boto.S3BotoStorage" Note: You should never expose your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY there is some reason why they are called SECRET. 6) Install AWS CLI on your machine. 7) Its time to move your files to AWS S3 bucket. $ aws s3 cp myfolder s3://mybucket/myfolder --recursive 8) After the previous step you can use the following command to view the contents of your bucket. $ aws s3 ls s3://mybucket 9) Grant public-read permission to everyone, add the below to your … -
Django 1.6 最佳实践: django项目的服务器部署
如果详细说明django项目的不熟的话,可能需要整本书才能说明清楚, 这里我们只从较高角度讨论. 1. 使用一台服务器 如果django项目较小, 也不会有太多用户访问的话, 我们可以使用一台服务器来部署. 此时我们需要以下部件: 关系型数据库: PostgreSQL 或 MySQL HTTP 服务器: Nginx + uWSGI, Nginx + gunicore 或 Apache + mod_wsgi 进程管理: Supervisord 或 init scripts NoSQL数据库 (为短时间数据存在): Redis用于cache和消息列队, Memcached用于cache, RabbitMQ为消息列队 2. 使用多台服务器 简单情景 如下图, 你需要至少两台服务器, 一台是数据库服务器, 另一台则是 WSGI application 服务器. 如果可能还可以增加CDN用于储存媒体文件, cache服务器用于储存缓存, 任务服务器用于单独运行CPU敏感的任务. 复杂情景 如下图, 你需要software-based或hardware-based 的 loading balancer, software-based的有HAPProxy, Varnish, Nginx. hardware-based的有Foundry, Juniper, DNS load balancer. 当然还可以使用cloud-based的, 例如Amazon Elastic Load Balancer, Rackspace Cloud Load Balancer. 3. WSGI Application 服务器 首先需要说明的是, 永远使用WSGI部署django项目. django 的 startproject 会为我们设置好wsgi.py文件, 这一文件中包含了部署django项目到wsgi服务器的默认设置. 最常见的WSGI服务器配置包括: Nginx + uWSGI Nginx + Gunicorn Apache + mod_wsgi 以下是这三者的一个简单对比表: 配置优势劣势 Nginx + uWSGI 使用纯C语言构造; 拥有许多优秀的特性和选项; 声称具有更好的性能 文档不够完整; 没有经过长时间测试 Nginx + Gunicorn Gunicorn使用纯Python构造; 声称具有更好的内存管理能力 Gunicorn和Nginx的文档不足; 没有经过长时间测试 Apache + mod_wsgi 存在已经, 经过长时间测试; 非常稳定; 在windows下可运行; 文档丰富 不提供 environment variable 支持; 设置较复杂 虽然现在有许多测试表明哪个组合更快, 但不要盲目的相信这些测试结果, 因为大多数的测试可能都是基于测试小页面而得到的结果, 因此与实际的情况可能相差甚远. 则三种组合在现实环境中都有大量的使用案例. 要想使任何一种配置达到高通量的要求都需要我们投入时间和精力来测试获得. 使用自己的服务器的缺点就是我们需要额外的系统管理员, 而不像使用PaaS平台那么简便. 4. 自动化部署 当我们设置服务器时, 不应该每次都使用ssh登录服务器, 再按照记忆一步一步的配置. 因为这样实在是太容易忘记某些步骤了. 服务器设置应当自动化, 并写成文档. 在django用户中, Ansible, SaltStack, Puppet和Chef是最流行的四款自动化部署工具. 这些工具似乎都需要长时间学习才能使用, 因为这些工具不是为一台服务器设置的, 而是针对多台服务器的. 以下是这些工具的基本功能: 远程通过apt-get或其他包管理系统安装软件包 远程运行命令 远程启动, 重启各项服务 记录远程运行的命令和其结果 创建或更新服务配置文件 为不同服务器载入不同的配置文件 部署和更新项目代码 比较表: 工具优势劣势 SaltStack 主要用push模式; 使用0mq传输快; 许多例子; 庞大的社区支持; 开源; 由Python写成 较复杂 Ansible 主要用push模式; 可使用Fireball模式加速传输; 不需要远程进程运行; 使用YAML语言设置; 开源; 由Python写成 新项目, 例子较少, 没有官方WSGI和Django配置例子 Chef 有许多例子; 庞大的社区支持; 开源 难学; 由ruby写成, 配置也是ruby语言; Puppet 庞大的社区支持; 开源 较难学; 由ruby写成; 配置文件由自定义DSL设置 Fabric和Invoke则是专注于远程运行命令, 常可以和以上四个工具配合使用. 现在的趋势是更多的使用SaltStack或Ansible, 因为使用Python写成的, 所以更利于Python用户深入了解. 但需要注意的是, 这些趋势会变化, 如果想了解最新的趋势, 需要我们多关注相关的博客. -
Creating a custom user model in Django 1.6 - Part 3
Hello everyone and welcome back to the third part of this tutorial series. If you haven't done so yet, make sure to checkout part 1 and 2 first.Last week we saw how to create and use admin forms with a custom user model. This week we will go through the process of creating a frontend login form. During this process we will also cover (part of) template inheritance, csrf, the messages framework, accessing the user from the template and Crispy forms. I know last week I announced that this week's post would also cover the admin login form but finally the admin login form will be covered next week. -
Django 1.6 最佳实践: 部署到PaaS (Platforms as a Service) 平台
如果你的django项目是一个小型项目, 或者你的公司是初创公司, 使用PaaS平台部署django项目可能是个不错的选择. PaaS平台既能节约时间, 又省去了自己部署服务器的麻烦. 有些大型的django项目也可以利用PaaS带来的好处. 但需要注意的是, 永远不要绑定到某个平台. 虽然这些平台为我们提供了非常好的代码, 数据库, 媒体文件的储存和依托, 但如果其收费发生变化, 服务发生变化, 那么我们将会变得措手不及. 因此, 我们开发项目时, 不能一开始便为某一平台开发, 而是需要注重通用性, 方便在各平台或自己的服务器质检切换. 1. 如何衡量PaaS 标准 在衡量各PaaS前, 我们首先需要查看PaaS是够符合项目的一些硬性标准, 比如在医疗领域, 可能需要符合HIPAA标准, 许多电子商务型的网站也需要SSL支持. 价格 比较一下项目所需要的配置在各个平台间的价格是最基本的考查方式. 但我们还需要考虑到当项目的访问人数增加, 高流量的配置需要增加的费用在各平台间有什么分别. 稳定性 稳定性也十分重要, 许多平台都会打出标语, 保证99.9999%及以上的在线稳定运行时间, 但这些可信度如何还需要我们自己来测试. 服务 我们还需要查看的是各平台是否有足够的员工为我们提供技术支援, 如果PaaS平台的员工人数不足, 那24x7的服务时间肯定是无法保证的. 扩展性 每个平台是否能够轻易的scale up也是一个基本的问题. 有时我们会面对突然增加的流量, 这时可扩展性就显得非常重要. 文档 每个平台是否提供足够的文档支持也十分重要. 地点 选择一个离客户距离较近的PaaS平台能增加客户的访问速度, 因此也是一个需要考虑的因素. 公司 PaaS平台的所属公司也是需要考虑的因素之一, 有一个稳定的后台公司支持才能保障平台的长期存在. 2. 如何部署到PaaS 保持环境一致 部署项目的环境应当与开发环境尽量保持一致, 这样才能利于维护. 自动化部署 我们可以使用Makefiles, Invoke等工具将部署的步骤自动化, 从而减少工作难度. 测试 自动化部署工具往往自带测试功能, 即将项目部署到一个测试的PaaS实例中, 一切正常后才部署到正式PaaS实例中. 备份 随时为突发灾难准备好备份, 并且将这些备份分别保存在本地和其他储存环境中.