urls.py:
url(r'^book/(?P<booktitle>[\w\._-]+)/(?P<bookeditor>[\w\._-]+)/(?P<bookpages>[\w\._-]+)/(?P<bookid>[\d\._-]+)/$', 'book.views.book', name="book"),
views.py:
def book(request, booktitle, bookeditor, bookpages, bookid, template_name="book.html"):
book = get_object_or_404(book, pk=bookid)
if booktitle != book.book_title :
redirect_to = "/book/%s/%s/%s/%s/%i/" % ( booktitle, bookeditor, bookpages, bookid, )
return HttpResponseRedirect(redirect_to)
return render_to_response(template_name, { 'book': book, },)
.
So the urls of each book are like this:
example.com/book/the-bible/gesu-crist/938/12/
I want that if there is an error in the url, then I get redirected to the real url by using book.id in the end of the url.
For example if I go to:
example.com/book/A-bible/gesu-crist/938/12/
the I will get redirected to:
example.com/book/the-bible/gesu-crist/938/12/
but I go to wrong url I will get this error:
TypeError at /book/A-bible/gesu-crist/938/12/
%d format: a number is required, not unicode
.
Why ?
What I have to do ?
Hi at all,
I have created a very simple blog at www.example.com with a only one page.
When I connect to www.example.com I see all posts inserted in the database ( in mysql ).
Now I want that every 60 seconds an ajax request check in the database if there are new posts. If there are new posts these will be inserted at the top above the old posts.
This is my question:
How can I through Ajax retrieve only new posts ( and so distinguish old posts and new posts ) ?
I have:
created translation strings in the template and in the application view.
run this command: django-admin.py makemessages -l it
and the file it/LC_MESSAGES/django.po has been created
run this command: django-admin.py compilemessages
and I receive: processing file django.po in /home/jobber/Desktop/library/books/locale/it/LC_MESSAGES
set the language code in settings.py: LANGUAGE_CODE = 'it-IT'
but.... translation doesn't work !!
I always see english text.
Why ?
I have:
* created translation strings in the template and in the application view.
* run this command: django-admin.py makemessages -l it and the file it/LC_MESSAGES/django.po has been created
* translated strings in the django.po file.
* run this command: django-admin.py compilemessages and I receive: processing file django.po in /home/jobber/Desktop/library/books/locale/it/LC_MESSAGES
* set this in settings.py:
LANGUAGE_CODE = 'it'
TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media", )
USE_I18N = True
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
but.... translation doesn't work !! I always see english text. Why ?
Hi at all, I need to create a simple web chat ( like facebook chat )
What language do I need to use ( server-side ) ?
Erlang ? PHP ? Python ? Ruby ? ecc
Are there any examples ?
Thanks ^_^
What's the best way to run a query so that spaces in the fields are
ignored? For example the following queries....
SELECT * FROM mytable WHERE username = "JohnBobJones"
SELECT * FROM mytable WHERE username = "John Bob Jones"
.
would find the following entries:
John Bob Jones
JohnBob Jones
JohnBobJones
.
I am using php or python but I think this doesn't matter.
I need to create a chat similar to facebook chat.
I am thinking to use ajax polling ( to send request every 2-3 seconds ).
Is this a good approach ? Or I need to use other server side languages like erlang and server-comet ?
Hi at all,
Tornado is a webserver + framework like Django but for real-time features.
On my server I don't have a python module or wsgi module so I thought
CGI.
Is there a way to get Tornado ( or Django ) works by using CGI folder ?
If yes, Could you explain me how do I do that ?
Is there a way to create a form from profile models ?
For example... If I have this model as profile:
class blogger(models.Model):
user = models.ForeignKey(User, unique=True)
born = models.DateTimeField('born')
gender = models.CharField(max_length=1, choices=gender )
about = models.TextField(_('about'), null=True, blank=True)
.
I want this form:
Name:
Surname:
Born:
Gender:
About:
Is this possible ? If yes how ?
I have these 2 models:
genre = (
('D', 'Dramatic'),
('T', 'Thriller'),
('L', 'Love'),
)
class Book(models.Model):
title = models.CharField(max_length=100)
genre = models.CharField(max_length=1, choices=genre)
class Author(models.Model):
user = models.ForeignKey(User, unique=True)
born = models.DateTimeField('born')
book = models.ForeignKey(Book)
I need to retrieve first_name and last_name of all authors of dramatic's books.
How can I do this in django ?
I want to use str(uuid.uuid4()) instead of the name uploaded.
I have this model:
class foo(models.Model):
pic = ThumbnailField(upload_to='pics', size=(200, 200))
I am uploading hello_world.jpg and I should save these named versions should be saved for example in 4ba9b397-da69-4307-9bce-e92887e84d2f.jpg.
How can I do that?
I am trying to connect to my webserver via ssh but I can't. When I insert the password then the terminal is blocked. This is what I see:
# ssh [email protected][email protected]'s password:
Why ?
In iptables there are no rules.
Please help :(
I have read that relational databases are a terrible way to do multicast messages like twitter.
So twitter saves every tweet only one times and then retrieve its in every stream ? or saves every tweet in every users's stream ?
I want to know why relational database ( like mysql or postgresql ) doesn't good for twitter-like application.
I use Postgresql + PHP.
Say I have this table:
Books ( id, title, year )
and this array of titles in PHP:
$titles = array ("bible","kafka","Book of Eli");
now I want update all rows where the title is in the $titles array above.
So I need a query like this:
UPDATE books SET year = '2001-11-11' WHERE title is in $titles;
Is is possible with one single query ? Or do I need to use FOR loop ?