我正在尝试使用 Django 模板系统作为 python 脚本中的工具来输出文件。我不需要 Django 框架的其他组件。
我按照说明将模板系统配置为独立模式,但是当我尝试使用template.loader.render_to_string()、template.loader.get_template()或 时,template.render(Content())我得到了AppRegistryNotReady异常:
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Run Code Online (Sandbox Code Playgroud)
settings.configure()如文档中所述,我有以下调用:
settings.configure(
DEBUG=DEBUG,
TEMPLATE_DEBUG=True,
TEMPLATE_DIRS=(
POSTS_DIR,
TEMPLATES_DIR,
PAGES_DIR,
),
)
Run Code Online (Sandbox Code Playgroud)
我也尝试添加INSTALLED_APPS=(),同样的问题。我只想使用模板系统。除了模板加载器之外我不需要任何东西,所以我可以使用extend模板。
我正在部署一个Django网页,我喜欢Django Debug 404页面和Django页面,当有python错误时.但是,这些不适合上网的网页.所以我做了一个自定义的404页面.但是,对我和我的IP地址,我想仍然有Django Debug页面出现.如果我将Debug设置为false,是否还有这样做?
所以在我的settings.py中我指定了两个数据库连接(见下文).
但是当我运行测试时,我只希望Django创建"默认"数据库.
有没有办法做到这一点?我尝试添加TEST_CREATE:False选项,但我想这只是因为某些原因而导致的Oracle?
我的settings.py片段:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'App1', # Or path to database file if using sqlite3.
'USER': 'webaccess', # 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.
},
'default_root': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', …Run Code Online (Sandbox Code Playgroud) 在制作时,我一直在尝试将djangosecure.middleware.SecurityMiddleware(来自http://pypi.python.org/pypi/django-secure)添加到我的设置中,但没有任何运气使它工作.
当我跑:
./manage.py checksecure
Run Code Online (Sandbox Code Playgroud)
一切都顺利通过.但我无法加载该网站.它给了我以下错误:
The webpage has resulted in too many redirects. Clearing your cookies for this site or
allowing third-party cookies may fix the problem. If not, it is possibly a server
configuration issue and not a problem with your computer.
Run Code Online (Sandbox Code Playgroud)
在本地,当我使用生产设置时,我收到一个页面错误:
Unable to make a secure connection to the server. This may be a problem with the server,
or it may be requiring a client authentication certificate that you don't have.
Run Code Online (Sandbox Code Playgroud)
我的终端然后充满了我无法解读的奇怪错误:
[12/Jan/2013 14:15:25] code …Run Code Online (Sandbox Code Playgroud) 我已ALLOWED_HOSTS正确设置,但我不断收到来自所有类型网站的请求,这些请求会导致出现"[Django] ERROR(外部IP):内部服务器错误".
如何忽略此特定错误?
我是新手,所以我可能做了些蠢事.运行python 3.3和Django 1.6.2.
当我通过命令行运行本地服务器时,这是我收到的错误"P/1.1 404 1712",浏览器上的错误是"找不到模块",异常位置指示我urls.py第22行;
document_root=settings.STATIC_ROOT)
Run Code Online (Sandbox Code Playgroud)
这是urls.py的一部分:
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'signups.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
Run Code Online (Sandbox Code Playgroud)
这是我的settings.py看起来的样子:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/whattheheck/static/'
# Template location
TEMPLATE_DIRS = {
os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "templates"),
}
if DEBUG:
MEDIA_URL = '/whattheheck/media/'
STATIC_ROOT …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已经讨论过了.但问题仍然存在,我没有任何解决方案.请帮忙.
我的平台是:Ubuntu 14.04 LTS,Python 3.4,MySQL 5.5,Django 1.7,Nginx 1.4.6和Gunicorn 19.1.1.
当我DEBUG = False在生产服务器中设置时,我的Django应用程序运行可能会持续半天.在那之后,烦人Server Error (500)总是出现在某些功能上,但不是每一个.如果我转身DEBUG = True,一切都会好的.
我也定了ALLOWED_HOSTS = ['*'].有人说它不应该是生产中的外卡.但我的应用程序是公开的,我应该如何设置它?其他人说它应该是'localhost'.但只能localhost访问服务器?为什么要去生产呢?
这个问题有标准解决方案吗?谢谢.
我正在关注django-disqus的文档,以便在我的项目中使用它.我已经在我的设置中安装了它,以及其他所需的设置(API key和short name).但是当我尝试运行这些命令时:
>>> from django.contrib.sites.models import Site
>>> Site.objects.all()
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
OperationalError:没有这样的表:django_site
我已经django.contrib.admin在我的设置中安装并在我的项目中使用它.那我错过了什么?
问:如何ALLOW_HOSTS在弹性beanstalk实例上设置django 以允许Elastic Load Balancer IP?
背景
我在弹性beanstalk上部署了django网站.网站域名被添加到ALLOW_HOSTS正常请求被django正确接受.
ALLOWED_HOSTS = ['.mydomain.com']
Run Code Online (Sandbox Code Playgroud)
Elastic Load balancer直接使用IP地址访问Elastic beanstalk实例以进行运行状况检查,因此下一行允许运行状况检查:
# add elastic beanstalk instance local ip
aws_ip = requests.get('http://169.254.169.254/latest/meta-data/local-ipv4', timeout=0.1).text
ALLOWED_HOSTS.append(aws_ip)
Run Code Online (Sandbox Code Playgroud)
但我仍然得到无效的HOST IP错误,似乎弹性负载均衡器公共IP访问了弹性beanstalk实例.有针对EC2部署的在线解决方案,因为您可以将HTTPD软件设置为在IP直接访问时设置http HOST标头.但我们无法在弹性beanstalk上配置apache.那么如何将弹性负载均衡器IP添加到ALLOW_HOSTS?
python django amazon-web-services django-settings amazon-elastic-beanstalk
我正在尝试做的是更改django项目中特定应用程序的迁移的默认路径,将其置于项目本身之外,但保持透明,保持使用makemigrations和迁移.可能吗?如果有,怎么样?
django ×10
django-settings ×10
python ×4
apache ×1
django-admin ×1
exception ×1
nginx ×1
ssl ×1
templates ×1