我正在使用 django 1.6
在我的设置中有这个,效果很好,
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
Run Code Online (Sandbox Code Playgroud)
但当我添加:`MEDIA_ROOT = os.path.join(BASE_DIR, 'media/'),
渲染模板时出现错误:
'tuple' does not support the buffer interface
Run Code Online (Sandbox Code Playgroud)
问题代码: <link href=" {% static 'bootstrap/css/bootstrap.min.css' %} " rel="stylesheet">
这两种设置之间是否存在某种冲突?我想做的就是为用户上传的文件提供服务,我应该将upload_to设置更改为静态目录吗?
有谁以前经历过这个或知道可能是什么问题
感谢任何帮助,谢谢
我有两个database兴趣,基本的和开发的:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| projectsdb |
| projectsdb_dev |
+--------------------+
3 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
在我的 django 文件中mysite/mysite/settings.py,我的数据库是这样声明的:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'projectsdb',
'USER': 'projectsdb',
'PASSWORD': 'notsecure',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
Run Code Online (Sandbox Code Playgroud)
允许的主机是:
ALLOWED_HOSTS = ['xxx.xx.xxx.xx'] # I replaced it for the example
Run Code Online (Sandbox Code Playgroud)
我在用于开发的端口 8006 上启动服务器:
$ python ./manage.py runserver …Run Code Online (Sandbox Code Playgroud) 我使用 django 3.1.1 和 Python 3.8.5。我想创建简单的博客。我使用一些旧代码,其中程序员可能使用 django 1.11,所以我改变了很多东西,但现在我陷入困境
我收到错误
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'mysite.wsgi.application' could not be loaded; Error importing module.
Run Code Online (Sandbox Code Playgroud)
当我尝试删除时
WSGI_APPLICATION = 'mysite.wsgi.application'
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class
Run Code Online (Sandbox Code Playgroud)
这是我的整个设置.py
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.8.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) …Run Code Online (Sandbox Code Playgroud) 我没有看到这个问题的回答版本,这真的让我感到困扰,因为我已经看到两者都被使用了。
在此示例中,“myapp”是创建的应用程序。
我一直看到用户在 INSTALLED_APPS 列表中设置他们的应用程序,如下所示:
INSTALLED_APPS = [
'myapp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Run Code Online (Sandbox Code Playgroud)
代替
INSTALLED_APPS = [
'myapp.apps.MyappConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Run Code Online (Sandbox Code Playgroud)
所以我有2个问题
当我在本地服务器上工作时(即http://127.0.0.1:8000/ ) ,我试图阻止 Sentry 将错误记录到我的 Sentry 仪表板。我希望哨兵将错误记录到仪表板的唯一时间是当我的代码投入生产时。我该怎么办?我在下面尝试过这个,但它不起作用:
if DEBUG == True
sentry_sdk.init(
dsn=os.environ.get('SENTRY_DSN', None),
integrations=[DjangoIntegration()],
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True
)
Run Code Online (Sandbox Code Playgroud)