background preloader

Django

Facebook Twitter

How to include multi-line html from django template into javascript variable. Django fixtures (from dumpdata) failing when testing. How to Store Your Media Files in Amazon S3 Bucket. In this article, I will show you how to use Amazon Simple Storage Service (S3) to store your media files in the cloud.

How to Store Your Media Files in Amazon S3 Bucket

S3 is known and widely used for its scalability, reliability, and relatively cheap price. It is free to join and you only pay the hosting and bandwidth costs as you use it. The service is provided by Amazon.com. S3 tends to be attractive for start-up companies looking to minimize costs. S3 uses a concept of buckets which is like a storage database. If you want to browse the files in a folder-like structure, you can use Transmit FTP client on Mac OS X. OK. 1. At first you will need to create a bucket at S3 and make it accessible for all visitors. 2.

Amazon Web Services provide a python library called boto for accessing the API. Pip install boto==2.19.0 pip install django-storages==1.1.8 3. Add the following to the settings.py: INSTALLED_APPS = [ # ... 4. Let's create a Profile model with avatar field. 5. Where the image source will look like " Conclusion.

Amazon s3 - Django: Only collect changed static files. Creating an app on Heroku with Django and NPM. Glyn Jackson - Freelance Django Developer Based in Manchester. 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.

Glyn Jackson - Freelance Django Developer Based in Manchester

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. Introduction to Django Selenium Testing.

Posted by Marco in Code, Django If you’ve never heard of Selenium, put simply, it’s a tool that allows you to create tests that are run in the browser and interact with your UI in the same way as if you were manually testing your website or app.

Introduction to Django Selenium Testing

It’s the de-facto standard to test complex Web UI interactions that usually involve a heavy use of JavaScript, and that’s probably the main use-case for it. Other than that, we also use it sometimes as a helper tool for cross-browser design (CSS) testing by running Selenium tests through different browsers and taking screenshots or recording videos. Selenium’s been around for a long time now, and is available in various programming languages, but up until Django 1.4 came along you couldn’t have your Selenium tests (easily) integrated with your Django test suite.

Since then, a new class named LiveServerTestCase, that your Selenium test classes can inherit from, was introduced. Installation. Python - Creating a fake request to render a view to a string in django. Obey the Testing Goat! Django merging two QuerySet using itertools. Python - In a django form, How to make a field readonly (or disabled) so that it cannot be edited. Python - How can I disable a model field in a django form. Python - Django creating a form field that's read only using widgets. Custom Widget Types for HTML5 Form Fields. Django/Ember Token Authentication. Authentication can be a real headache.

Django/Ember Token Authentication

Thankfully, Django REST Framework and Ember have taken care of the heavy-lifting already. As I’ve previously detailed, implementing session-based authentication with Django and Ember is not as hard as you might think. Now I’d like to say the same thing for token-based authentication. In token-based authentication, every user in the database is assigned a unique token. The flow of authentication then works like this: You send a username and password to the APIThe API validates the credentials and returns that user’s tokenYou include the token in the header of every request going forward to prove that you are already authenticated.

HTML5 and Django Form Inputs - Bryan Pieper's Blog. I recently went through the fairly painless of process of upgrading thepiepers.net to html5.

HTML5 and Django Form Inputs - Bryan Pieper's Blog

This will allow me more flexibility in the future as more browsers expand their support for html5. In addition, html5 has a number of improvements over html4 that will make my front-end work a little easier. In the process of upgrading the site, I implemented the following Internet Explorer overrides for html5 elementsFixed display issues for non-html5 elementsImplemented Django html5 form inputs With any front-end update to your site, there is always the Internet Explorer factor. Finally, the Django form inputs do not support the new input types like “email”, “tel” and “url”, just to name a few. From django.forms.widgets import Inputfrom django import forms class Html5EmailInput(Input): input_type = 'email' class Html5URLInput(Input): input_type = 'url'... class Html5Form(forms.Form): email = forms.CharField(widget=Html5EmailInput()) url = forms.CharField(widget=Html5URLInput())... Adding search to a Django site in a snap.

Search is a feature that is — or at least, should be — present on most sites containing dynamic or large content. There are a few projects around to tackle that. Here’s a non-exhaustive list: djangosearch, django-search (with a dash), django-sphinx. Those search engines are great, but they seem like overkill if you just need a simple search feature for your CMS or blog. Front end admin toolbar. Searchengine. This tutorial will show you the basic of Django when we will make a google search engine front end in the framework.

searchengine

I've googled out an interesting python module called ​web_search which allows to get search results from few search engines and dmoz. Download web_search.py from that page Create a new project called “google” Advanced search for a specific Django model. Updated version of #31. Sql - Database trouble in Django: can't reset because of dependencies. Django - Excluding some fields in Inline Admin Interface. Mysql - Django drop all tables from database. Extending the Django Admin Interface. This blog post is just a collection of notes I took along the way that might help you if you’ve had a play with the Django Admin and now are wondering how to get a little more out of it.

Extending the Django Admin Interface

I have just spent a few weeks working on the first phase of an anlaytics dashboard application that is built using a mixture of Django, jQuery and Flash with the Isotoma crew. The project needed some way to set up the different sites and regions and rather than create these screens “by hand” we decided that the default Django Admin functionality would do this job well.

When I first saw the Django Admin screens I was shocked at how much you get “for free”. Having designed your database you can start editing it using screens that look better and work better than many CMSs. Despite Django Admin’s obvious abilities it is often thought of as being “only for the developer” and not something that you’d let a client loose on. My Approach I like things to be simple. Url - How to get the current urlname using Django. Python - Can a dictionary be passed to django models on create. Dynamic query builder with AND/OR. How do I do a not equal in Django queryset filtering. How do I do a not equal in Django queryset filtering. Bootstrap your Django admin in 3 minutes - Python / Javascript / Django coding notes by Riccardo Forina. Posted November 16th, 2012 in django, bootstrap, django-admin-bootstrapped.

Bootstrap your Django admin in 3 minutes - Python / Javascript / Django coding notes by Riccardo Forina

Python: How to get a value of datetime.today() that is "timezone aware" Python - How to display "x days ago" type time using Humanize in Django template. Incomplete Format. Convert Django Model Instances To Dictionaries. I just searched for a method to convert a model instance to a dictionary in Django and the top few results were a bunch of custom methods in Django Snippets and Stack Overflow.

Convert Django Model Instances To Dictionaries

I was about to use one of those when I clicked on one last link that showed me a better solution. There is a method already built into Django that does exactly what I want: django.forms.models.model_to_dict. As I pointed that out to a coworker, he showed me that that’s basically the same output as the .values() method in the queryset api. If you don’t specify a value to retrieve, it will retrieve the whole model instance as a dictionary. Here’s the output of these two pieces of code: Dynamic Models with Django. Asset Managers. Python - Django load local json file. How can I get the domain name of my site within a Django template. Using Django lazily translated strings in JSON. Compiler error - msgfmt command not found when compiling git on a shared hosting. Translations in django 1.5 - DjangoForum. Hi there, I think this should be pretty simple/straight forward, but it's not.

Translations in django 1.5 - DjangoForum

I want to support many languages for my project. I followed a few tutorials and read the doc about it. I think I'm doing everything ok, but I'm still not able to get my text translated. I have two languages, "fr" and "en". Django models ForeignKey and custom admin filters…»Between engineering and real life. The problem: Having a foreign key between models in django is really simple. For example: Speciality: So if you want dynamic choices in the admin drop down you have to write a method that will return list with options and bind it to the form(as shown in Django forms ChoiceField with dynamic values…) which is used by admin.

This will work great but if you decided to add this column in admin`s list_filter you will see all element from the connected model in filter. How to limit them to the same list used for the form choices? Solution: The simplest solutions is to extend RelatedFilterSpec, overwrite its default choices and add a single row to the model: Python - Django view returning json without using template. Django tip: URL redirect shortcut. Bottom Line Up Front: Here’s a succinct, elegant way to do simple redirects in Django. Sometimes in a web app, you need to perform a simple redirect, pointing one URL to another. For example, in a current project, I need the / URL to redirect to /shop. I don’t need any complicated routing; I just need to rewrite one URL to another. (And, as happens sometimes, I don’t want to fiddle with the web server conf to do it.) The Django docs suggest creating a custom view function that takes care of the redirection. . # urls.py urlpatterns = patterns('', (r'^$', views.redirect_to_shop), ... ) # views.py from django.http import HttpResponseRedirect def redirect_to_shop(request): return HttpResponseRedirect("/shop/") ...

Writing a custom view seems like a bit of overkill here. Python - Using crontab with django. Python - For Django models, is there a shortcut for seeing if a record exists. Asset Managers. Django models, custom functions. Python - In Django, how does one filter a QuerySet with dynamic field lookups. Some Lessons Learnt from Messing with Django and AngularJS. 2012/09/s3-and-cloudfront-for-static-and-uploaded-files-on-django-works-on-heroku/ This isn't the only way to make this happen but it worked well for me. Daemonizing a tornado app. 'str' object has no attribute 'META' error while creating a ModelForm in django. B:dev: Get Graphite run for a Django project. This post is intended first of all to memorize my experience of getting the Graphite system work. Graphite system. Django Broken pipe in Debug mode. TDDjangoTutorial. Python - Serving large files ( with high loads ) in Django.

Django + Tornado = Chat by Skis / Toys / Fun. Tornado with django. Python - Getting serialized json objects from django templates. Django Project Structure — The Definitive Guide to Deploying Django Applications on Heroku. Organize django applications in packages and modules. When you create a django application you have one module to add your model classes the models.py and one module to add your views the views.py (also called actions in other web frameworks), and there are possibly other modules like forms.py and admin.py.

This is perfectly fine when you have a small application with a couple of classes in your models.py and few functions in your views.py. TDDjangoTutorial. How to install Django on JustHost (and maybe other shared hosts) If you search Google for "how to install Django on JustHost" you may be surprised to find tens of thousands of articles claiming that it can't be done and none claiming that it can. Well, it can and here's how: Zgohr/Django-CMS-Example. Linux - Installing memcached for a django project. Caching websites with Django and Memcached…»Between engineering and real life.

After Caching web sites and web applications and When to use caching for web sites its time for a little sample. This sample shows the usage of Memcached for server-side application cache. The installation part is taken from my Ubuntu so it may differ depending from your OS/distribution. Writing a Selenium Test Framework for a Django Site (Part 3) See Part 1 and Part 2 for the rest of this series. Now that we’ve figured out how to get Selenium tests to run in various browsers on different operating systems, we should probably get some actual test cases written. Localization - How to use django.views.i18n.set_language() function. Django internationalization and translations problem.

How to implement breadcrumbs in a Django template. Breadcrumbs in Django with Templates — Martin – Geber · de. Historias, Aventuras y Notas. Desde hace unos días he estado probando Jade, un motor de plantillas inspirado en Haml. Me encanta la sintaxis tan limpia que tiene, muy similar a lo que estoy acostumbrado en python. Estaba trabajando en un proyecto con Django así que me puse a usar Jade de una vez, les muestro como lo integré a Django, lo cuál fue, verdaderamente sencillo. En el repositorio en github de Jade dice que hay una implementación en Python de Jade llamada pyjade, así que hay que instalarla primero: Ya que la instalamos, editamos un par de líneas en nuestro settings.py de nuestro proyecto en Django, específicamente la sección TEMPLATE_LOADERS: A partir de aquí es coser y cantar, hacemos nuestras plantillas con jade, añadimos nuestra url y en su caso la vista correspondiente y ¡voilà¡ Un caso sencillo sería algo así, con una plantilla base y un home: También podemos escapar el comportamiento por defecto de esta manera: Solo hay un problema con pyjade en Django, y es que no funcionan los mixins actualmente.

Integrate existing blog code into Django-CMS. Python UnicodeEncodeError: 'ascii' codec can't encode character. Python UnicodeEncodeError: 'ascii' codec can't encode character UnicodeEncodeError: 'ascii' codec can't encode character u'\xa1' in position 0: ordinal not in range(128)

Python - django form got multiple values for keyword argument. Django: get URL of current page, including parameters, in a template. 33 projects that make developing django apps awesome — elweb. Django - Mod_python error: ImportError: Could not import settings. Python - Django - ImportError at /blog. No module named urls. Python - No module named index. Python - Django + mod_wsgi + apache: ImportError at / No module named djproj.urls. Deploying Django. Python - Django newbie deployment question - ImportError: Could not import settings 'settings'

Python - Defining Constants in Django. Allow dotted names in urlconf · Issue #41 · pydanny/django-mongonaut. Django and mongodb - Daniel Greenfeld and Audrey Roy. MongoEngine Users. How to create a basic blog in Django » Configuring the automatic admin. MongoDB. Auto generate admin.py. Django: admin.py doesn't exist.

Can syncdb in django with mongoengine · Issue #172 · MongoEngine/mongoengine. Python - how do you install django older version using easy_install. Translation. The Pinax Tutorial #3: Internationalization of the application. Python - right way to use if else in django template. Python - django render template within a template. Cross Site Request Forgery protection.