简体   繁体   English

Docker Container Running 但它抛出错误 Template does not Exist

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

Hi I'm New In Docker I Have Created A Django Application Its Running in Local machine Good But When I try To run In docker Container its Run Properly But When I sent Request The Found 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"]
# 

My Docker File Look Like that我的 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

My Template folder Is in Blog app templates/blog/templtes.html我的模板文件夹位于 Blog app templates/blog/templtes.html

when i run #docker-compose up then my image server is start but then i sent request from my brouser the i get the error page当我运行#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

some one can help me to fix this error有人可以帮我解决这个错误

According to your Dockerfile, you must copy your django project from one folder to another and you didn't set workdir.根据您的 Dockerfile,您必须将 django 项目从一个文件夹复制到另一个文件夹,并且您没有设置 workdir。

Instead of this:而不是这个:

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

Try this way:试试这样:

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

Note: Don't forget to re-build this Dockerfile.注意:不要忘记重新构建此 Dockerfile。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM