TemplateDoesNotExist at /accounts/ (Django With Flutter)

116

What I can see is that the screens folder is on the root but not inside the accounts folder it's self. For that you have to explicitly mention in the templates configurations within settings. You have to mention the "BASE_DIR, 'name of the folder where the templates are'". Here how it has to be written.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'screens')],
        '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',
            ],
        },
    },
]

Secondly, you have to give the path of the file within in the views in such manner.

    return render(request, 'screens/login_screen.dart', context)

Hope that helps.

Share:
116
Admin
Author by

Admin

Updated on December 17, 2022

Comments

  • Admin
    Admin 11 months

    I am trying to connect Flutter with Django. Flutter and Django alone seems to be fine,working without error. But when i am trying to combine both together, an error pops up that says:

    TemplateDoesNotExist at /accounts/

    Here is the cause of the problem

    from django.shortcuts import render, HttpResponse
    
    
    def home(request):
        return render(request, '../screens/login_screen.dart')
    

    It says that directory does not exists.

    enter image description here

    As you see above the directory exists. What is the problem can somebody help?

    Template:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [],
            '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',
                ],
            },
        },
    ]
    
    • Muhammed Mahir
      Muhammed Mahir almost 4 years
      Can you show the template configuration in the settings file.
    • Admin
      Admin almost 4 years
      @MuhammedMahir i updated question.You can see it now.