投稿された大量のコード/構成についてお詫び申し上げます-しかし、私はエラーを見つけるのに苦労しており、誰かがそれを見つけられることを望んでいました. django/virtualenv を使用するのはこれが初めてなので、おそらく何かばかげていると思います。記録として、私は Python 2.7 と Django 1.5 を使用しています。私は共有サーバーを使用していますが、必要なすべての依存関係を備えた仮想環境があります。
これで、.urls のすべての管理ページがコメント アウトされているときに、Django のようこそ画面が表示されるようになりました。ただし、ユーザーと呼ばれる1つのアプリを処理するために、sqlite3(本番環境では推奨されていないことを知っています)データベースをセットアップしています。
Python シェルを使用して、タイプ User のオブジェクトをデータベースに正常に追加できます。したがって、データベースの問題ではありません。私が知る限り、ある時点でWebページをレンダリングしようとすると、モジュールユーザーを呼び出していますが、それを見つけることができません. そのため、プロジェクト ディレクトリの外から呼び出している必要があります。おそらくパスに何かを追加する必要があると思いますか? しかし、何を追加しますか?
virtualenv site-packages ディレクトリに、プロジェクトの内部フォルダー、つまり project/project (アプリユーザーの内部) へのシンボリック リンクがあります。だから私の推測では、そのシンボリックリンクを変更して、代わりに外側のプロジェクトディレクトリを指すようにする必要がありますか?
私のプロジェクト構造は次のとおりです。
/project
/project/project_db
/project/manage.py
/project/users/__init__.py
/project/users/admin.py
/project/users/models.py
/project/users/tests.py
/project/users/views.py
/project/project/__init__.py
/project/project/settings.py
/project/project/urls.py
/project/project/wsgi.py
さて、関連ファイル:
/project/project/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'project_db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
#...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'users',
)
次: /project/users/models.py
from django.db import models
# Create your models here.
class User(models.Model):
CRAWFORD = 'CR'
CARPENTER = 'CA'
NOTAPPLICABLE = 'NA'
HALL_CHOICES = (
(CRAWFORD, 'Crawford'),
(CARPENTER, 'Carpenter'),
(NOTAPPLICABLE, 'Not Applicable'),
)
hall = models.CharField(max_length=2,choices=HALL_CHOICES,default=NOTAPPLICABLE)
email = models.CharField(max_length=256)
password = models.CharField(max_length=32)
supervisor = models.ForeignKey('self',blank=True, null=True, default=None)
def __unicode__(self):
return self.email + " " + self.hall
最後に: .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export PATH=$PATH:$HOME/bin:$HOME/virtual/lib/python2.7/site-packages/django/bin:$HOME/website/project
export PYTHONPATH=$PYTHONPATH:$HOME/virtual/lib/python2.7/site-packages:$HOME/website/project