簡體   English   中英

Docker Container Running 但它拋出錯誤 Template does not Exist

[英]Docker Container Running But it throws the error Template does not Exist

嗨,我是 Docker 的新手,我創建了一個 Django 應用程序,它在本地機器上運行良好但是當我嘗試在 docker 容器中運行時它運行正常但是當我發送請求時發現錯誤模板不存在

 Dockerfile
#syntax=docker/dockerfile:1
#FROM ubuntu:latest
FROM ubuntu:latest
FROM python:3.8-slim-buster
WORKDIR /app
#COPY requirements.txt requirements.txt

#RUN pip3 install -r requirements.txt
#
#CMD python . /manage.py runserver 0.0.0.0:8000"""
# pull the official base image

# set work directory


# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN apt-get update&& \
    apt-get -y install sudo
RUN apt-get install -y tesseract-ocr
RUN apt-get install -y build-essential libpoppler-cpp-dev pkg-config python-dev mupdf

RUN apt-get install ffmpeg libsm6 libxext6  -y

RUN apt-get install -y default-jre
RUN apt-get install -y default-jdk


RUN apt-get update
RUN apt-get install -y python3-pip
RUN pip3 install --upgrade pip
#RUN pip3 install virtualenv
#RUN python3 -m virtualenv env
#RUN source env/bin/activate
COPY requirements.txt requirements.txt

RUN pip3 install -r requirements.txt
# copy project
COPY . /app

EXPOSE 8000

CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
# 

我的 Docker 文件看起來像那樣

docker-cpmpose.yml
version: "3"
   
services:
   web:
       build: .
       command: python3 manage.py runserver 0.0.0.0:8000
       ports:
           - 8000:8000

Folder Structure

    Directory: E:\djangoproject\blogproject


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        22-12-2022     19:39                Blog
d-----        22-12-2022     19:39                Blogproject
d-----        22-12-2022     19:40                venv
-a----        22-12-2022     19:46         192512 db.sqlite3
-a----        21-12-2022     18:02            153 docker-compose.yml
-a----        22-12-2022     15:51           1097 Dockerfile
-a----        24-12-2021     13:00            689 manage.py
-a----        20-12-2022     13:09            578 requirements.txt

我的模板文件夾位於 Blog app templates/blog/templtes.html

當我運行#docker-compose up 然后我的圖像服務器啟動但是然后我從我的瀏覽器發送請求我得到錯誤頁面

TemplateDoesNotExist at /
blog/pages.html 
Request Method: GET
Request URL:    http://localhost:8000/
Django Version: 3.2.8
Exception Type: TemplateDoesNotExist
Exception Value:    
blog/pages.html 
Exception Location: /usr/local/lib/python3.8/site-packages/django/template/backends/django.py, line 84, in reraise
Python Executable:  /usr/local/bin/python3
Python Version: 3.8.16
Python Path:    
['/app',
 '/usr/local/lib/python38.zip',
 '/usr/local/lib/python3.8',
 '/usr/local/lib/python3.8/lib-dynload',
 '/usr/local/lib/python3.8/site-packages']
Server time:    Fri, 23 Dec 2022 05:53:42 +0000
Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

This engine did not provide a list of tried templates.
Error during template rendering
In template /app/Blog/templates/blog/base.html, error at line 0

有人可以幫我解決這個錯誤

根據您的 Dockerfile,您必須將 django 項目從一個文件夾復制到另一個文件夾,並且您沒有設置 workdir。

而不是這個:

COPY . /app  #here only you copied but didn't set where to copy

試試這樣:

COPY ./app /app    #here copied Django project from one folder to another.
WORKDIR /app

注意:不要忘記重新構建此 Dockerfile。

暫無
暫無

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

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