background preloader

Archives

Archives

Django - Static file not found The GitHub Blog Django Projects — Django Best Practices Location Templates typically live in one of two places, inside the application or at the root level of a project. We recommend keeping all your templates in the project template directory unless you plan on including your application in multiple projects (or developing it as a open source “reusable” application). In that case, it can be helpful to ship with a set of sample templates in the application, allowing it to work out-of-the-box or serving as an example for other developers. Naming Django’s generic views provide an excellent pattern for naming templates. They have been well thought out and tested.It makes your code immediately understandable to new developers picking up your Django code. Most generic view templates are named in the format: [application]/[model]_[function].html For example, creating a template to list all of the contacts (Contact model) in my address book (address_book application), I would use the following template: address_book/contact_list.html

Writing Robust Bash Shell Scripts : David Pashley.com Many people hack together shell scripts quickly to do simple tasks, but these soon take on a life of their own. Unfortunately shell scripts are full of subtle effects which result in scripts failing in unusual ways. It’s possible to write scripts which minimise these problems. How often have you written a script that broke because a variable wasn’t set? chroot=$1 ... rm -rf $chroot/usr/share/doc If you ran the script above and accidentally forgot to give a parameter, you would have just deleted all of your system documentation rather than making a smaller chroot. david% bash /tmp/shrink-chroot.sh $chroot= david% bash -u /tmp/shrink-chroot.sh /tmp/shrink-chroot.sh: line 3: $1: unbound variable david% Every script you write should include set -e at the top. Using -e gives you error checking for free. command if [ "$?" could be replaced with command || { echo "command failed"; exit 1; } or if ! What if you have a command that returns non-zero or you are not interested in its return value?

A Guide to Testing in Django - Toast Driven For many people, testing their Django applications is a mystery. They hear that they should be testing their code but often have no clue how to get started. And when they hit the testing docs, they find a deep dive on what functionality is available, but no guidance on how to implement. This is the first in a series of blog posts to try to help alleviate this & get everyone on the testing bandwagon. I'll assume you've never done any testing before but that you're comfortable with Python & Django. We'll be walking through adding tests to the perennial tutorial Django app. Before we dive into code, let's introduce some basic concepts & talk about how to think/go about testing. Why Should You Test Your Code? "Code without tests is broken by design." - Jacob Providing automated tests for your code is a way to repeatedly ensure, with minimal developer effort, that the code you wrote to handle a task works as advertised. This is not to say that tests solve everything. Types Of Testing Tooling . . . .

Fear Those Tiers Udi Dahan December 2007 Summary: Tiers and networks are not to be taken lightly, in any architecture. This article chronicles the author's journey toward a robust and scalable architecture. (7 printed pages) Contents IntroductionCanned AnswersBack to the Drawing BoardDistribution Trumps OOConclusionCritical-Thinking QuestionsFurther StudyGlossary Introduction I was horrified: My beautiful tiered architecture was buckling under the stress tests—at one tenth of the expected load of the system. The only redeeming thing about this situation was that I had learned the hard way to do performance tests early in the project; with that skill mastered, I thought that there might still be enough time to save the situation. Since then, I've learned that tiers and networks are not to be taken lightly, in any architecture. Canned Answers Anyway, object-orientation (OO) was the religion of the day, and the Unified Modeling Language (UML) was the language that we spoke. Back to the Drawing Board Conclusion

How and why to use django-mongokit (aka. Django to MongoDB) Here I'm going to explain how to combine Django and MongoDB using MongoKit and django-mongokit. MongoDB is a document store built for high speed and high concurrency with a very good redundancy story. It's an alternative to relational databases (e.g. MySQL) that is what Django is tightly coupled with in it's ORM (Object Relation Mapping) and what it's called now is ODM (Object Document Mapping) in lack of a better acronym. So we start by defining a MongoKit subclass: All of these class attributes are features of MongoKit. As you can see it's pretty easy to work with and it just feels so pythonic and obvious. The query methods one() and find() can take search parameters which limits what you get back. So, what would it take to be able to do this MongoKit business in a running Django so that you can write Django views and templates that interface with your Mongo "documents". Then, with that in place all you need to get a connection are these lines: So, what's so great about this setup?

AI Computer Vision: Scala vs. Haskell vs. Python Functional programming is on the upswing, but should you bet your career on it, or is it a short-lived technology fad? I have long wanted to use functional programming professionally and for the last year I have. Mainly Scala, written in Haskell style, plus some real Haskell programming. Here is my impression of Scala and Haskell compared to my benchmark language, Python. Scala Scala is a functional object oriented hybrid language running on the JVM. Issues It is very complexIt is a kitchen sink languageConfusing to keep Scala collections and parallel Java collections apart Eclipse Plugin Scala IDE for Eclipse The Scala Eclipse plugin is very solid, but not quite as good as the fantastic Java support. Syntax highlighting Code completionDebuggerShows compile errors with explanationRudimentary refactoringJump to definition Monad and Applicative Functor Two very important concepts in functional programming are monad and applicative functor. Scalaz Haskell There is a steep learning curve for Haskell.

10 Insanely Useful Django Tips There are quite a few great little tricks and tips one could use on their Django projects that would speed up development and save many headaches in the long run. From basic to obscure, these tips can help any skill-level of programmer become more adept with Django and all it's glory. Django is an excellent framework for Python. While it may not get as much ink as other popular frameworks like Rails, it is just as much a polished framework as any of the rest. It puts plenty of emphasis on the DRY principle (Don't Repeat Yourself) in clean coding by automating many of the processes in programming. For some reason, projects tend to be moved around in location from time to time. My default Django settings file has changed over time to now include settings that do not depend on the location of the project on the file system. Rob's post has excellent code examples for setting up your Django installation in a very flexible way. One of the core philosophies of Django is loose coupling. Templates

Sylvain Zimmer | Blog Two weeks ago, while waiting for my flight to San Francisco at an airport in Paris I stumbled on a coding challenge by NASA to optimize the solar arrays of the International Space Station. I’ll let the video explain: Being very interested in Optimization for my soon-to-be-unveiled new startup, I was quite excited and promptly downloaded all the required material to spend my 10-hour flight hacking ;-) The rules forbid talking about code while the contest is running but since it just finished, I would like to share how I built my solution with tools like OpenOpt, EC2 Spot Instances and MongoDB. Disclaimer: Shortly after landing I was the top Python solution and 10th overall but I couldn’t spend enough time on my code while abroad to stay that high in the charts. The contest TopCoder made a Java simulator available along with the detailed description of the problem. So the whole contest was basically about minimizing the shadows cast by the front solar arrays and the station itself.

(48) What does an ideal Django workflow setup look like Eventually Coding - Luc Stepniewski's Blog In a Django project, I have a template that is used by two urls, which is quite common (generic views, using ‘create_object’ and ‘update_object’). The problem is that I had to add a supplementary menu just when the template is loaded from the ‘update’ generic view, and not from the ‘create’ generic view. Making the difference between the two urls calls at the template level is a problem because it’s managed by generic views, so the same template is used. Anyways, there are several possibilities: In urls.py, use the ‘template_name’ variable, where you can speficy a specific template for this url(). That is instead of using the default <model>_form.html. Another solution, is to find a way to use a variable in the template that would be different wether the template has been loaded by update_object or create_object. In our urlpatterns in urls.py, we can use the ‘extra_context‘ variable (takes a dictionnary as parameter). We can also use, in urls.py, the ‘context_processors’ variable.

Java Bien!

Related: