Monday, August 13, 2007

Motion Detector With Reflector

begin with Django 6 - a real page II

Another feature is access to the templates, the dictionary elements, objects and arrays. Most seem obvious, but worthy of mention.

Dictionary:



In [15]: from django.template import Context, Template
In [16]: t = Template ("" "I'm osoba.nazwisko {{}}. {{Osoba.imie {{}}}}
osoba.nazwisko ....: The latest film I had {{}} osoba.liczbaZyc live "" ")
In [18]: james = {'name': 'James',' name ':' Blonde ',' liczbaZyc ': '5'}
In [19]: c = Context ({'person': james})
In [20]: t.render (c)
Out [20]: 'I'm a Blond. James Blond \\ nThe latest film I had five live '



object (of course to their own classes of objects referenced in the same way):



In [24]: from django.template import Context, Template
In [25]: import datetime
In [26]: d = datetime.date (2007, 7, 14)
In [27]: d.month
Out [27]: 7
In [28]: t = Template ('Month date.month {{}} {{year Lord date.year }}.')
In [29]: c = Context ({' date ': d})
In [30]: t.render (c)
Out [30]: 'Month of seven years Lord 2007. "
In [31]: c = Context ({'date': datetime.date (2007, 6, 14)})
In [32]: t.render (c)
Out [32]: 'Lord Month 6 years , 2007. "



array elements (upper and calling - you can call the method, but only parameterless, most spots can be used repeatedly, do not use parentheses when calling):



In [48]: from django . template import Template, Context
In [49]: t = Template ('Now with the agent's number two: {{ agenci.2.upper }}.')
In [50]: t.render (Context ({'agents': ['James', 'Bolo', 'Olo']}))
Out [50]:' Now with the agent's number two: OLO. "



As for the presentation layer, these elements are really a lot. In the event that someone was afraid that his name conflict occurs, an item search order after the period is as follows (for ab): a key in the dictionary (a ['b']), an attribute of an object (ab), calling (ab ()) , a reference to an array (a [b]). Still
word about handling exceptions in methods. Can cause that the exception was ignored (obviously not a good way of handling each exception.) The Django template happens when the exception object is to set a special variable: silent_variable_failure = True
can also protect you from calling methods (for example, one that has side effects):



def write (self ): = True
zapis.alters_data



Another important element is to preserve the templates at the time to appeal to non-existent variable. If it is not reconfigured Django is incorrect references are ignored (empty string). It is worth remembering, if only because the case-sensitive.

Saturday, June 16, 2007

To Build A Home Cinematic Orchestra Piano Sheet

Latest Django in Ubuntu

Today there is a new Django in Ubuntu (7.04, Feisty Fawn) - Version 0.96-1, which is in accordance with the currently released version. Nice because it saves a few problems (such as that described my short URL s). This will also be modeled accurately on DjangoBook.

Saturday, June 9, 2007

Belkİn F6d4050 Lİnux Drİver

I return to the start of the news

decided to start again, read the news, of course, continue treating the RSS as the primary source of information. But I apologized the good old Usenet and NNTP. He encouraged me to show Michael Rutkowski in telewizorni remembered as once discussed on the pages pl.rec.sport.koszykowka eg Tim Duncan, which is indeed a lot said yesterday MR. I immediately turned tina (best ever NNTP reader) and ordered the list of groups. So far, only python, denunciations and basketball. I've brought this effect, I found an interesting link: Set Python films, including Django (only installation). There are also some other interesting categories.

Friday, June 1, 2007

Difference Between Intermediate And Senior Gloves

Django 5 - a real page

In another approach, I want to generate "Real" part. Now you have to use a template system offered by Django. Finally, after he is. Once it is. From reading the fourth chapter DB learned that in templates: access to variables is obtained by writing {{varname}} , code blocks are marked as {% instructions for making %} and we have access to the filters (using the tries to check and show time soon. Another curiosity that offer templates used in Django is able to generate a template object by specifying a string containing the template (except that of course is the ability to specify the file containing the template, but it is standard). I start the classic tests: . / Manage.py shell and then : from django.template import Template, then
t = Template ("I'm {{name}}. {{Name}} {{name}}")
and print t which will only show us where the t. object to what they write in DB templates that are pre-compiled to an internal form, ready to generate the page. Therefore, the error in the template (eg t = Template ('{% user%} had errors ") ), revealed at the time of the appointment of a template object to life. Generating the template takes place in a context that is represented by an object class Context . In this short presentation code (the code directly from your sticky, I thought that this form of presentation will be better, of course, write what is after the colon):

In [27]: django.template from import Context, Template
In [28]: t = Template ("I'm {{name}}. {{name}} {{name}}")
In [29]: c = Context ({' Name: "Blond", "name": "James"})
In [30]: t.render (c)
Out [30]: 'I'm Blond. James Blond '




course we see what happens, as context will have defined a variable:



In [33]: from django.template import Context, Template
In [34] : t = Template ("I'm {{surname }}.{{ name}} {{name}}")
In [35]: c = Context ({"name": "Blond"})
In [36]: t.render (c)
Out [36]: 'I'm Blond.Blond'



As you can see , nothing bad will not happen. Generated an empty string. In my opinion, is a plus (CakePHP generate, if I remember correctly, the error in such cases). Page designer can so easily extend it with new elements that relate to variables not yet defined and not wait for the programmer.

last element in this entry is to enable interactive testing wielolinijkowych templates (useful information for those who have not benefited Python), multiline strings placed just between the triple quotes
"" long string "" "
:



In [39]: from django.template import Context, Template
In [40]: t = Template ("" "I'm {{surname }}.{{ name}} {{name}}
....: The latest film I had {{}} liczbaZyc live
....: How about it "" ")
In [42]: c = Context ({" name ":" Blonde "," name ":" James "," liczbaZyc ": 5}) In [43]: t.render (c)
Out [43]: 'I'm Blond.JamesBlond \\ nIf I have a new movie 5 live \\ nco you so '





Examples include repetition (Imports, re-definitions of objects) only to show the full picture of what is happening in the program. During one session, of course, there is no need to import multiple classes or creating the same template.
DjangoBook fourth chapter is quite big, so its contents extend to the few entries in which I gradually expanded information about the templates.

Monday, May 14, 2007

Electric Blanket Battery Operated

begin with Django 4 - first page

high time to see the effects of some of their own work, because so far, is mostly automatic performed for me all the steps.
time configurations used URLs, which had already changed (the file urls.py

). The first exercise in the DB (Chapter 3) as simplified by me as follows:
django.http import from HttpResponse import datetime def
current_datetime (request):
html = "This is% s"% datetime.datetime. now () return HttpResponse (html)




Save this file
views.py
.
You are once again on the side to fire up a terminal and
. / Manage.py shell and then
:
from mdjango.mbegin.views import * (wszystkie kolejne sprawdzenia będę najpierw przeprowadzał w konsoli, więc nie będę juz pisał o jej odpalaniu).
Odpalamy current_datetime() , powinien nam się pojawić błąd. Wynika on z tego, że próbowałem wykorzystać konsolę do wypisania HTTPResponse. Teraz już zmiana konfiguracji URL-i: dodajemy import pliku z widokami i konfiguracje przekierowania w przypadku wywołania adresu http://localhost:8080/czas/. plik
urls.py
wygląda teraz tak:

from django.conf.urls.defaults import * from mdjango.mbegin.views import *
urlpatterns = patterns ('',
(r '^ time /', current_datetime) (r '^ admin /', include ('django.contrib.admin.urls')),
)




I results show .... error. By the way it shows up as a django errors, as for me, quite clearly and that is what I would expect the information about the error. There is a stack, is to ask, is the configuration. I guess I no longer have to write about yet another plus. I also noticed the ability to switch between viewing modes, information about the error. Same error is:
AttributeError at / time / 'function' object has no attribute 'rindex'
it means that the DB is to the front for my Ubuntu. Like I said destination URLs, you can write only from version 0.96 and I have 0.95. For now, I will not lift version (we know the different workaround.) The solution is to write the function name as a string preceded by the name of the application and module. So finally it looks like this:


from django.conf.urls.defaults import * import * from mdjango.mbegin.views
urlpatterns = patterns ('',
(r '^ time /', 'mbegin . views.current_datetime '), (r' ^ admin / ', include (' django.contrib.admin.urls'));
)




simplifying the way I made yet another error: In terms of simplification is not written request parameter for the function current_datetime, it is clearly needed. After you fix bugs you will see a modest, but his own, the first page made using django. Now I will go downhill, but that's the next episode. And today, the last element to have the correct time, set
TIME_ZONE = 'Europe / Warsaw'
(or, if you will be set) in settings.py

, no, unless you live in the same time zone as Chicago

Sunday, May 6, 2007

Cities & Knightsunlock

begin with Django 3 - Database

I begin with Django 3
Since I have already prepared a database, then it would be worthwhile to use it. Until that is found only in the 17th chapter DB python mysite / manage.py inspectdb
(DB:
python mysite / manage.py inspectdb> mysite / myapp / models.py ). Generated is something like this:
class Categorie (models.Model): id = models.IntegerField (primary_key = True) name =
models.CharField (maxlength = 600)
models.TextField description = (blank = True) class Meta
: db_table = 'categories'



Because the tables have different names adapted to the framework, so their names are in the plural. It seems that Django uses a simple rule, subtract from the plural 's' and you have the singular. Does not always verify that the DB write to review and clean up the generated model will do it later, according to the principles described in the said 17th section The other puzzling thing is the value of maxlength (database fields are varchar (200) and model 600), you will need to decipher how the character encoding. Unfortunately, directly in the DB's on this subject did not write.
To check whether the model works, you can use
. / Manage.py shell
. If you have previously installed the ipython, we have at the moment quite a nice work environment with a database, and in fact with its model. I dare to believe that it will also be a good place to start such unit tests. To use the model of some table, enough to enter
project.app.models import from nazwa_modelu

ie to import from mdjango.mbegin.models Categorie
, then you're ready Categorie.objects.values \u200b\u200b() (the value of the records), or Categorie.objects.count () (number of records). Another big plus for Django, you can see immediately how the model before using it in an application. For now, only I used phpmyadmin to check whether the model is correct, most of the required operations can now be done from the shell, with the assurance that you are connected to the right base, etc.

Thursday, May 3, 2007

How To Get 25 Credits On Poptropica

begin with Django 2

We go further, according to what is written on the previously created (http://piotrbla.blogspot.com/2007/05/zaczynam-z-django.html) project site. In the settings.py file for a set portion of the database (since
DATABASE_ENGINE to DATABASE_PORT After setting up the database generate the first application: . / manage.py startapp mbegin (generated on the project website: mdjango python / manage. py startapp [appname] ). arises directory (For me
mbegin
) where there are empty files for models and views (and models.py views.py ). In the generation of a small problem with the encoding pliterek in the name of the administrator, for now forgive (resigns pliterek), and then you will need it explores the topic. Another thing which gives quick results is the admin panel (small instantaneous jumps to 6 of Chapter DB). In the file settings.py section INSTALLED_APPS add an entry
'django.contrib.admin'
later run. / Manage.py syncdb (DB: python manage.py syncdb ), which generates administrative tables in the database. When asked about the superuser should immediately create it (later it is done according to the DB using a script / django / contrib / auth / create_superuser.py . I am using locate create_superuser.py I found this script at the following locations: / var/lib/python-support/python2.4/django/contrib/auth/create_superuser.py / var/lib/python-support/python2.5/django/contrib/auth/create_superuser.py / usr / share / python-support/python-django/django/contrib/auth/create_superuser.py
The third stage of the DB generation panel is to append urls.py
(The draft)
urlpatterns = patterns ('',
(r '^ admin /', include ('django.contrib.admin.urls')),
)
in my case it was uncommenting this line in rzeczonym file. I'm trying to check, I consider that unnecessarily restarted before the mini server (changes occur immediately after recording the file). Unfortunately (but somehow I survived) resulted in new changes that the existing home page reports an error (at this point it is worth noting that all the messages about Django that I've seen so far led to the solution). Works while subpage / admin

http://localhost:8080/admin/
log in, and appears fully READY aesthetic administrative side, the ability to view and filter data, add users, groups, etc. In other words, something that should be everywhere.
Basic user management completely out of my head, as compared to other frameworks again looks promising.

Samantha Anderson At Hom

begin Django

just started trying to use django, which is so much good had read (at least here
). I would like the
Curious: the occasion to talk about Django, he went out as usual, the problem of pronunciation. Well-informed sources say that it is said dżangoh (d voiceless, oh oh passing in;)). As I went walking companion:
DjangoBook
, will seek solutions to problems in the first and accessible to the terms of the GNU

book. At the moment, not all its chapters are written (most are), so sometimes you will need to support the search engine.

starter kit I already have: Linux (Ubuntu DD-> EE-> FF), Python, Django, MySQL. All to find in Synaptic. Of course, you can use django with other common databases (and without any database, which also used to verify). In DjangoBooku (hereinafter DB) write that check whether you have the mysql-python, I have in Ubuntu python-MySQLdb and it seems that it is precisely this package. In addition, of course, one can check if it works phpmyadmin (unfortunately, at the moment of Linux IMHO the lack of a better tool, you can still try to kexi). worth mentioning on the occasion of my knowledge of Python. I wrote a few (very few) scripts (in size, as I say, the screen). I read a little about the language (including one mid-sized book), is interested in him for a long time. Professionally, however, always was programming in other languages. What _mi_ in Python like the most is attached batteries as indentation and force (as someone will take classes in programming for beginners in any language like C, you will know why this is a plus language). Knowledge of Django: I heard that a good and nothing more. Meaning: Python 4 / 10, Django 1 / 10.

database to my project, I was almost ready, so you probably will not be specifically bent over her. At the beginning of the terminal, go to your directory with the parties (in my public_html directory and write: django-admin
startproject mdjango
(DB write:
django-admin.py startproject mysite
, but the installation package django added somewhere in an elegant script and knows that it starts python). From what I know at the moment, Django can store several applications in one project.
project database stores settings, options, Django, and App.
arise following files: __init__.py , manage.py, settings.py, urls.py . What you will need to write what they are. Yes resulting page, you can immediately check with the built-in mini http server. Just run it (in the directory mdjango):
. / Manage.py runserver
(DB again given the long version: python manage.py runserver ). I just have a default port (8000) busy, so get the error: Error: That port is already in use. Port changes trywalnie:
. / Manage.py runserver
8080 (DB: python manage.py runserver 8080). After entering the http://localhost:8080/ acting immediately see the project page with instructions. Time for a first evaluation: I have a few tried and tested frameworks (including RoR and CakePHP) Django wins at this stage, the time to come to that point was just short as possible.

Wednesday, March 21, 2007

Pokemon Shiny Gold Evee

Deleting backup files

known to delete files '* ~' the backup in a directory write
rm * ~ .* ~ , some people like to write a yet-Rf. Do not delete it but we backup files in subdirectories. To do this, You can use this magic command: find. /-name '* ~' ~ / bin fi
try deleting the directory that contains no temporary file ends with a message: rm: missing operand , I treat it as information that there was nothing to delete. If someone is not fit, you simply add the-f (plowing), or the command will look like this:

find. /-Name '* ~'