2

私は django と Web フレームワークの開発にまったく慣れていないため、組み込みの django モデルを使用してテーブルを作成し、syncdb コマンドを実行して自動的に作成することに疲れました。ただし、作成に問題があります これが私のモデルです

from django.db import models

class User(models.Model):
    username=models.CharField(max_length=100,primary_key=True)
    password=models.CharField(max_length=100)

そしてデータベース構成

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'djangousers',                      # Or path to database file if using sqlite3.
        'USER': <my username>,                      # Not used with sqlite3.
        'PASSWORD': <my password>,                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
    }
}

そして、これは私が得るエラーです。

Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 100, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 202, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 185, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 162, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/thor/scripts/django/quiz/dbs.py", line 4, in <module>
class User(models.Model):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 52, in __new__
kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range

どんな助けでも大歓迎です。前もって感謝します

4

2 に答える 2

2

ここでモデルを定義しているようです: /home/thor/scripts/django/quiz/dbs.py

アプリ モジュールのルートにあり、名前がmodels.py.

詳細については、こちらを参照してください: https://docs.djangoproject.com/en/dev/topics/db/models/#using-models

于 2011-11-17T19:42:36.943 に答える
0

Django には独自の User モデルがあることをご存知ですか? すでに完了していることに時間を無駄にしないでください。(それが Django の全体的な考え方です)

詳細については、https ://docs.djangoproject.com/en/1.3/topics/auth/ を参照してください。

于 2011-11-18T00:29:24.180 に答える