Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TemplateDoesNotExist in Django and React

when i run python manage.py runserver

In Backend, it show template does not exist

In Front-end, it show 500 error message

In my settings.py, I have specified:

import os

BASE_DIR = os.path.dirname(os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))))
SECRET_KEY = '-05sgp9!deq=q1nltm@^^2cc+v29i(tyybv3v2t77qi66czazj'
DEBUG = True
ALLOWED_HOSTS = []
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'build')],
        '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',
            ],
        },
    },
]

In ProductList.js

componentDidMount() {
    this.setState({ loading: true });
    axios
      .get(productListURL)
      .then(res => {
        console.log(res.data);
        this.setState({ data: res.data, loading: false });
      })
      .catch(err => {
        this.setState({ error: err, loading: false });
      });
  }
like image 732
Zin Myo Swe Avatar asked Oct 27 '25 13:10

Zin Myo Swe


1 Answers

Can be solve this error by running

npm run build in terminal

this command is auto build UI folder in frontend.

After that, i run

python manage.py collectstatic

It Solved!!!

like image 169
Zin Myo Swe Avatar answered Oct 30 '25 03:10

Zin Myo Swe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!