Hi all
I'm trying to test django, I using the tutorial frome django:
http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01
I'm having problem with the admin-function, urls.py file give me
errors. I have read that the tutorial is wrong. I have used the
installed files frome django 1.0.2. Just uncomment the lines whats
should activate the admin function. But I can't access anny page att
all.
I have read step by step, what I'm doing. Maybe litle overkill.
---------
Python Version:
Python 2.5.2
Operatingsystem:
Ubunut Linux Hardy.
Operatingsystem status:
New installation. Only installed the following application:
vim
wget
kernel:
2.6.24-21-openvz
Hardare:
This is a virtutalmachine, OpenVZ.
----
1. Unpack the django package.
tar -zxvf Django-1.0.2-final.tar.gz
2. Install the django package.
cd Django-1.0.2-final
python setup.py install
3. Create project
cd /root
mkdir django
cd django
django-admin.py startproject mysite
4. Edit database settings in settings.py file.
cd mysite
vim settings.py
Added following in the database block.
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2',
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = '/root/django/mysite/database.db' # Or
path to database file if using sqlite3.
#DATABASE_USER = '' # Not used with sqlite3.
#DATABASE_PASSWORD = '' # Not used with sqlite3.
#DATABASE_HOST = '' # Set to empty string for localhost.
Not used with sqlite3.
#DATABASE_PORT = '' # Set to empty string for default. Not
used with sqlite3.
5. Syncdb
python manage.py syncdb
Added a adminaccount.
6. Create a app.
python manage.py startapp polls
7. Edit app-model
vim polls/models.py
Added the following:
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
8. Activating models
vim settings.py
Added:
mysite.polls to the INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls',
)
Created the databases:
python manage.py syncdb
9. Confirm that the models is working.
python manage.py shell
from mysite.polls.models import Poll, Choice
Poll.objects.all()
[]
import datetime
p = Poll(question="what's up?", pub_date=datetime.datetime.now())
p.save()
p.id
1
p.question
"what's up?"
10. Starting the webserver
python manage.py runserver 192.168.1.157:80
Working fine.
11. Activate the admin site.
11.1 Edeting settings.py
Added the line: django.contrib.admin to the INSTALLED_APPS block.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls',
'django.contrib.admin',
)
python manage.py syncdb
11.2 Edeting the urls.py file.
Uncomment lines:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below and add
'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/(.*)', admin.site.root),
)
12. Start the server, surf to http://192.168.1.157/admin/, get error:
Environment:
Request Method: GET
Request URL: http://192.168.1.157/admin/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
77. request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
resolve
179. for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
_get_urlconf_module
198. self._urlconf_module = __import__
(self.urlconf_name, {}, {}, [''])
Exception Type: IndentationError at /admin/
Exception Value: unexpected indent (urls.py, line 4)
13. Start the server, surf to http://192.168.1.157, get error:
Environment:
Request Method: GET
Request URL: http://192.168.1.157/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
77. request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
resolve
179. for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
_get_urlconf_module
198. self._urlconf_module = __import__
(self.urlconf_name, {}, {}, [''])
Exception Type: IndentationError at /
Exception Value: unexpected indent (urls.py, line 4)
----------
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---