I am following a tutorial on Django which is basically a series of short todos that lead to the building of a web application to manage bookmarks.
So far I've: - installed Django 1.4.2 properly - created the project and its folders (be low my question is related to that...) - set the database engine (sqlite3) - defined views.py to show a simple message on a webpage (Congrats youve created a webpage...) - defined an entry for the main page in the urls.py. See below:
from django.conf.urls.defaults import *
from bookmarks.views import *
urlpatterns = patterns('',
(r'^$', main_page),
)
so, so f, everything worked like a charm.
Then I had to work on the database. I've:
-created the data model by typing the following in models.py:
from django.db import models
class Link(models.Model):
url = models.URLField(unique=True)
-defined the INSTALLED APPS in settings.py as follow:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django_bookmarks.bookmarks',
)
here's the tricky part. I had to sync the data tables. So I typed:
manage.py syncdb
but I got an error message saying: there is no bookmarks module
So I checked the folder structure and it was as follow
django_bookmarks
├── bookmarks
│ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── django_bookmarks
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
So, at that point, I moved the "bookmarks" folder into django_bookmarks (the subfolder one). When I did "syncdb" it worked fine. Then I replaced the "bookmarks" to its original place just like shown on the tree above. So I continue thinking I triumphed...
I then had to work on the data Bookmark Data Model. I followed the tutorial's directive and typed the following in bookmarks/models.py:
from django.contrib.auth.models import User
class Bookmark(models.Model):
title = models.CharField(maxlength=200)
user = models.ForeignKey(User)
link = models.ForeignKey(Link)
To create the table I had to type "manage.py syncdb" again. BUT then comes the error message: no bookmarks module. So I cut-pasted the "bookmarks" folder again in the "django_bookmarks" (the subfolder one) thinking it would work.. but it didnt.. it printed about 17 lines (Python traceback) which line 15 (or 16..) was about models.py (models.CharField(maxlength=200)) and the line in
Python27/lib/site-packages/django/db/models/fields/__init__
and the very last message being:
TypeError: __init__() got an unexpected keyword argument 'maxlength'
I don't see what's wrong. I followed the tutorial (except when I could not sync tables and I resorted to pasting the "bookmarks" folder elsewhere...) ...and the folder tree seems pretty standard. Why it does not find the "bookmark" module?
Any help will do :-) thanks!
there's no maxlength
attribute of CharField. but there is max_length
. you're missing the underscore