I could not find TEMPLATE_DIR in settings.py, to tell where my template files are.
Also, when I go to my index.html (that you can see below), parsing does not work (for exapmle {{ title }}
, which you can see below in views.py ).
Why does it ( {{title }}
) not work?
I think that I am so close to make it work, but I can't.
Also, I could not find any related topic in SO.
SO, What I want to see is this:
But I see this:
index.html looks like:
index.html source:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<div class="container">
<h1>First Blog </h1>
<h2>{{ title }}</h2>
<h3>Posted on {{ date }} by {{ author }}</h3>
<p>{{ body }}</p>
</div>
</body>
</html>
view.py seems like this:
# Create your views here.
from django.shortcuts import render_to_response
from blog.models import posts
def home(request):
return render_to_response('index.html' {'title :'My First Post'})
~
models.py seems like this:
from django.db import models
# Create your models here.
class posts(models.Model):
author = models.CharField(max_lenght = 30)
title = models.CharField(max_lenght = 100)
bodytext = models.TextField()
timestamp = models.DateTimeField()
Here is what I did before:
Python 2.7.2 installed
user@domain.com [~]# python -V
Python 2.7.2
Django 1.5 installed
user@domain.com [~]# python
Python 2.7.2 (default, Mar 27 2013, 12:07:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django import get_version
>>> get_version()
'1.5'
I had problems about creating my project (django-admin.py startpriject mysite),
username@domain.com [~/www/domain/]# django-admin.py startproject mysite
-bash: django-admin.py: command not found
it was a PATH issue, and solved at the end, thanks to SO, I have successfully created my project.
Then I modified models.py like this (to create a simple blog):
from django.db import models
# Create your models here.
class posts(models.Model):
author = models.CharField(max_lenght = 30)
title = models.CharField(max_lenght = 100)
bodytext = models.TextField()
timestamp = models.DateTimeField()
MySQL-python 1.2.4 installed
username@domain.com [~]# python
Python 2.7.2 (default, Mar 27 2013, 12:07:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
I have created a mysql database and a user, added user to the database and gave all the privileges (done all in bluehost frontend panel).
I had problems about database update,
python manage.py syncdb
thanks to SO, that has been also solved.
user@domain.com [~/www/domain/mysite]# python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no):
Why does it ( {{title }} ) not work?
What should I change?
Should I re-install something?