簡體   English   中英

在 AWS 上部署 Django 網站時出現 SQLite 錯誤

[英]SQLite error when deploying Django Website on AWS

我是這里和編程方面的新手,所以請憐憫:我正在用 Maximilian Course 制作我的第一個 Django 項目。 我做了Django博客。 我在部署時遇到了一些錯誤,但現在我在部署並嘗試訪問我在 AWS 上的網站后遇到了這個錯誤:

Django - deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver

但在調試頁面上還有更多內容:在模板/var/app/current/blog/templates/blog/index.html 中,錯誤位於 l

在第 25 行,這是加粗的:

{% url 'single_post' slug=all_posts.0.slug %}

all_post 是一個查詢集類型的上下文變量。 這條線有問題嗎? 在本地機器上一切正常

所以我找到了這個解決方案:

Django - deterministic=True 在運行時需要 SQLite 3.8.3 或更高版本 python manage.py runserver

所以我是這樣理解的:

  1. 在 ubuntu 終端輸入: sudo apt install python3.10-venv來安裝環境

  2. 然后在 Visual Studio 的 Django 項目中,我輸入python3 -m venv django_my_site來創建虛擬環境

  3. 現在我點擊“+”打開這個環境並輸入pip3 install pysqlite3pip3 install pysqlite3-binary

  4. 之后我輸入python3 -m pip freeze > requirements.txt

我得到 requirements.txt 文件,看起來像這樣:

asgiref==3.6.0
Django==4.1.4
Pillow==9.3.0
pysqlite3==0.5.0
pysqlite3-binary==0.5.0
sqlparse==0.4.3
  1. 我還在 settings.py 中添加了 3 行:

     __import__('pysqlite3') import sys sys.modules['sqlite3'] = sys.modules.pop('pysqlite3') DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } }
  2. 之后,我再次打包項目的所有必要文件夾和文件。

  3. 在 AWS 的應用程序版本中,我再次上傳 zip 並部署。

  4. 我重新啟動了實例,服務器狀態正常,但仍然出現 sqlite 錯誤。

日志文件中一些有趣的部分:

2023/01/02 15:10:03 [warn] 344#344: *157 using uninitialized "month" variable while logging request, client: 192.155.90.118, server: , request: "\00\85\00\00\81\A0cw\9BP\A3\F8U[Z0\EB\A0=\8Ba\CC!\F8ؼ\DD\FB\C9\C0"
2023/01/02 15:10:03 [warn] 344#344: *157 using uninitialized "day" variable while logging request, client: 192.155.90.118, server: , request: "\00\85\00\00\81\A0cw\9BP\A3\F8U[Z0\EB\A0=\8Ba\CC!\F8ؼ\DD\FB\C9\C0"
2023/01/02 15:10:03 [warn] 344#344: *157 using uninitialized "hour" variable while logging request, client: 192.155.90.118, server: , request: "\00\85\00\00\81\A0cw\9BP\A3\F8U[Z0\EB\A0=\8Ba\CC!\F8ؼ\DD\FB\C9\C0"

Jan  2 18:11:17 ip-172-31-87-96 web: create_deterministic_function("django_date_extract", 2, _sqlite_datetime_extract)
Jan  2 18:11:17 ip-172-31-87-96 web: django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
Jan  2 18:14:34 ip-172-31-87-96 web: Invalid HTTP_HOST header: '54.147.47.55'. You may need to add '54.147.47.55' to ALLOWED_HOSTS.

所有日志文件:

https://files.fm/f/27h4mjf9t

鏈接到我的存儲庫:

https://github.com/Stanotech/my_site.git

settings.py 中的一些設置:

from pathlib import Path
from os import getenv


ALLOWED_HOSTS = [
    getenv("APP_HOST")
]


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog'
]

ROOT_URLCONF = 'my_site.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            BASE_DIR / "templates"

        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'my_site.wsgi.application'

__import__('pysqlite3')    
import sys    
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    BASE_DIR / "static"
]

MEDIA_ROOT = BASE_DIR / "uploads"
MEDIA_URL = "/user-media/"

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

SESSIONS_COOKIE_AGE = 9999  

您是否嘗試設置環境以使用 python 3.7

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM