I'm kinda new to django, and python, so I'm probably gonna make myself
look a bit stupid. Here goes anyway:
As a simple django (1.0) project, (using python 2.6) I've decided to
write a blog application. Here it goes:
blog/urls.py
--------------
from django.conf.urls.defaults import *
urlpatterns = patterns('myblog.blog',
(r'','views.listposts'),
)
blog/models.py
-------------------
from django.conf.urls.defaults import *
urlpatterns = patterns('myblog.blog',
(r'','views.listposts'),
)
blog/models.py
--------------------
from django.db import models
from django.http import HttpResponse
from tinymce.widgets import TinyMCE
import re
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
pub_date = models.DateTimeField('date
written',auto_now_add=True, null=True)
change_date = models.DateTimeField('date
changed',auto_now=True, null=True)
def __unicode__(self):
return self.title
def save(self, force_insert=False, force_update=False):
... Here come some long lines of code I think is irrelevant, but ask
me if you think they are....
blog/views.py
-----------
from django.shortcuts import render_to_response as RenderToResponse
from myblog.blog.models import Post
def listposts(request):
a = Post.objects.all()
a[0].title = 'hihi'
a[0].content = 'haha'
print a[0].title
print a[0].content
return RenderToResponse('blog/showlist.html',{'postlist': a});
blog/showlist.html
-----------------------
<h1>Hello</h1>
<ol>
{% for post in postlist.all %}
<li>{{ post.title }}</li>
<div>{{ post.content|safe }}</div>
{% endfor %}
</ol>
As you may have guest, I expected the first post title to be 'hihi'
and it's content to be 'haha'. Well... it's not. I still get the same
post I have in my database. Yet the "print" lines give me the right
post content in the server debug messages.
Any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---