background preloader

Django Packages : django reusable apps, sites and tools directory

Django Packages : django reusable apps, sites and tools directory

Five Days to a Django Web App: Day Three, Coding - The Daily Build Thanks for coming back for Day Three! [Note: Sorry this post is a day late. It was all ready to go late yesterday, but some of the code included below triggered a bug either in WordPress or ScribeFire and the whole post got mangled. Progress So Far Yesterday we built some mockups, just HTML and CSS — nothing active. Armed with these mockups, we’re ready to get started coding. Foundation MySQL First, go to your web host’s control panel and create two MySQL databases for this project. You’ll get an error/warning if the test database exists when you first run tests. Set up the same databases on your local system: bash$ mysql -u root Welcome to the MySQL monitor. Then generate a skeleton for your project: django-admin.py startproject YOURPROJECT. Then dive right in to settings.py and change a few things: To make it easier to use the same settings file to test both locally and on your host, I add the following to my settings.py to set MEDIA_ROOT and TEMPLATE_DIRS: Adding Some Meat bash$ . <!

Serving Static Content With Django A question that is frequently asked by new Django programmers is: "How can I serve static content (css, images, javascript) with the Django development server?". This article is my attempt to answer that question by demonstrating the best practices way to do so. Why Doesn't Django Serve Static Content Automatically? Well, Django (and python in general) is built around the idea that it is better to be explicit than implicit. This means that Django doesn't force us to put all of static content into a single, specific folder or tree, we can set it up however we like. This flexibility is what Django provides for us at the cost of not being able to automatically detect / serve our static content--which is why you are reading this article :) Where Should I Put My Static Content? In general, the convention I like to use is to put all static content in my project directory underneath the 'static' folder. Which allows me to have a good looking URL schema for my projects. Configure Your Settings

Django Userena - Accounts for your Django application Writing your first Django app, part 4 This tutorial begins where Tutorial 3 left off. We’re continuing the Web-poll application and will focus on simple form processing and cutting down our code. Write a simple form Let’s update our poll detail template (“polls/detail.html”) from the last tutorial, so that the template contains an HTML <form> element: polls/templates/polls/detail.html A quick rundown: Now, let’s create a Django view that handles the submitted data and does something with it. polls/urls.py url(r'^(? We also created a dummy implementation of the vote() function. polls/views.py This code includes a few things we haven’t covered yet in this tutorial: request.POST is a dictionary-like object that lets you access submitted data by key name. As mentioned in Tutorial 3, request is a HttpRequest object. After somebody votes in a question, the vote() view redirects to the results page for the question. This is almost exactly the same as the detail() view from Tutorial 3. Now, create a polls/results.html template: Amend views

Django aggregation tutorial — The Uswaretech Blog - Django Web Development By : Shabda Raaj One of the new and most awaited features with Django 1.1 was aggregation. As usual, Django comes with a very comprehensive documentation for this. Here, I have tried to put this in how-to form. Jump to howtos or Get source on Github. Essentially, aggregations are nothing but a way to perform an operation on group of rows. To do these operations Django added two new methods to querysets. aggregateannotate When you are have a queryset you can do two operations on it, Operate over the rowset to get a single value from it. The thing to notice is that option 1, will create one row from rowset, while option 2 will not change the number of rows in the rowset. In sql terms, aggregate is a operation(SUM, AVG, MIN, MAX), without a group by, while annotate is a operation with a group by on rowset_table.id. Ok enough talk, on to some actual work. Find the total number of employees. In sql you might want to do something like, select count(id) from hrms_employee Which becomes, The sql is

Web Forms You are here: Home Dive Into HTML5 Diving In Everybody knows about web forms, right? Make a <form>, a few <input type="text"> elements, maybe an <input type="password">, finish it off with an <input type="submit"> button, and you’re done. You don’t know the half of it. Placeholder Text The first improvement HTML5 brings to web forms is the ability to set placeholder text in an input field. You’ve probably seen placeholder text before. When you click on (or tab to) the location bar, the placeholder text disappears: Here’s how you can include placeholder text in your own web forms: Browsers that don’t support the placeholder attribute will simply ignore it. Ask Professor Markup Q: Can I use HTML markup in the placeholder attribute? Autofocus Fields Web sites can use JavaScript to focus the first input field of a web form automatically. To solve this problem, HTML5 introduces an autofocus attribute on all web form controls. Here’s how you can set a form field to autofocus: What’s that? To sum up:

clemesha/hotdot - GitHub Semantics You are here: Home Dive Into HTML5 Diving In This chapter will take an HTML page that has absolutely nothing wrong with it, and improve it. Parts of it will become shorter. Parts will become longer. All of it will become more semantic. Here is the page in question. The Doctype From the top: This is called the “doctype.” Microsoft came up with a novel solution. This idea spread like wildfire, and soon all major browsers had two modes: “quirks mode” and “standards mode.” In his seminal work, Activating Browser Modes with Doctype, Henri Sivonen summarizes the different modes: Quirks Mode In the Quirks mode, browsers violate contemporary Web format specifications in order to avoid “breaking” pages authored according to practices that were prevalent in the late 1990s. (You should read the rest of Henri’s article, because I’m simplifying immensely here. Now then. That happens to be one of the 15 doctypes that trigger “standards mode” in all modern browsers. This is the HTML5 doctype: That’s it. <!

Related: