[英]Serving Multiple Domains in Django
I currently have 2 domains that I want to share a single Django project via the use of Apache (and wsgi) I've used the following guide that I have found here: http://www.fir3net.com/Django/how-to-serve-multiple-domains-from-within-a-single-django-project.html 我目前有2个域,我想通过使用Apache(和wsgi)共享一个Django项目。我使用了我在这里找到的以下指南: http : //www.fir3net.com/Django/how-在单个django-project.html中提供多个域
To note: Domain 1 isn't using a database but domain2 is. 注意:域1不使用数据库,但域2使用数据库。 And I currently have a single database configured within the main settings.py file.
我目前在main settings.py文件中配置了一个数据库。
The issue I first had is that the template for domain1 was found but for domain2 it was unable to locate it. 我首先遇到的问题是找到了domain1的模板,但是对于domain2却找不到它。 After some troubleshooting I added the TEMPLATE_DIRs to the domain2_settings.py file.
经过一些故障排除后,我将TEMPLATE_DIRs添加到domain2_settings.py文件中。 Even though I would of expected this to be picked up by the main settings.py file.
即使我希望这会被主要的settings.py文件拾取。 Now I am getting an error that domain2 is unable to find a database and from the debug output it shows that there is no database assigned.
现在,我收到一个错误,即domain2无法找到数据库,并且从调试输出中可以看到没有分配数据库。 Even though I would of expected the database settings to be be pulled from the main settings.py file.
即使我期望从主settings.py文件中提取数据库设置。
Heres a summary of my layout: 以下是我的布局摘要:
/opt/
`-- django
|
`-- myproject
|-- __init__.py
|-- domain1
| |-- __init__.py
| |-- domain1.wsgi
| |-- domain1_settings.py
| |-- domain1_urls.py
| |-- models.py
| |-- tests.py
| |-- views.py
|-- domain2
| |-- __init__.py
| |-- domain2.wsgi
| |-- domain2_settings.py
| |-- domain2_urls.py
| |-- models.py
| |-- tests.py
| |-- views.py
|-- manage.py
|-- settings.py
|-- templates
| |-- domain1-base.html
| |-- domain2-base.html
`-- urls.py
settings.py settings.py
[root@william myproject]# cat settings.py
# Django settings for myproject project.
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '123', # Or path to database file if using sqlite3.
'USER': '123', # Not used with sqlite3.
'PASSWORD': '##########', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '' # Set to empty string for default. Not used with sqlite3.
},
}
domain2_settings.py domain2_settings.py
[root@william myproject]# cat domain2/domain2_settings.py
from settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SITE_ID = 2
ROOT_URLCONF = 'domain2.domain2_urls'
TEMPLATE_DIRS = (
"/opt/django/myproject/templates"
)
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',
'domain2',
)
Am I going about this the correct way (ie multiple domains, single project, apache and using a single database)? 我是否要以正确的方式(例如,多个域,单个项目,apache和使用单个数据库)进行操作?
The issue was I still had a settings.py and urls.py file within the domain2 folder. 问题是我在domain2文件夹中仍然有settings.py和urls.py文件。 Once I removed these the issue was resolved.
一旦我删除了这些,问题就解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.