How to connect django and React js but getting Error

391 views
Skip to first unread message

Vineeth

unread,
Oct 26, 2020, 5:56:13 AM10/26/20
to Django users
I am using django 3.1 version how to connect django and react  i am trying to connect but 
getting Error like TemplateDoesNotExist at /index.html  i attached my folder structure and error image
Templates DIRS.PNG
Error.PNG
Static folder structure.PNG

Farai M

unread,
Oct 26, 2020, 6:01:11 AM10/26/20
to django...@googlegroups.com
Why don't you use django rest framework API then separate your front end to your back end.That why you will not have to deal with integration issues

On Mon, Oct 26, 2020, 11:55 AM Vineeth <vinee...@gmail.com> wrote:
I am using django 3.1 version how to connect django and react  i am trying to connect but 
getting Error like TemplateDoesNotExist at /index.html  i attached my folder structure and error image

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/09f5e196-12b7-44f0-a7fd-52dd8ce035cdn%40googlegroups.com.

Samuel Nogueira

unread,
Oct 26, 2020, 7:08:38 AM10/26/20
to django...@googlegroups.com

Please can you show me your views.py?

 

-----------------------------------------------------------------------------------------------------

Samuel Nogueira Bacelar

 

GitHub: https://github.com/SamuelNoB

 

Linkedin: https://www.linkedin.com/in/samuel-nogueira-87800b1aa/

 

-----------------------------------------------------------------------------------------------------

--

Samuel Nogueira

unread,
Oct 26, 2020, 7:13:05 AM10/26/20
to django...@googlegroups.com

Also you should follow Farai’s recommendation and use DRF in your applicaiton.

 

-----------------------------------------------------------------------------------------------------

Samuel Nogueira Bacelar

 

GitHub: https://github.com/SamuelNoB

 

Linkedin: https://www.linkedin.com/in/samuel-nogueira-87800b1aa/

 

-----------------------------------------------------------------------------------------------------

 

Ayser shuhaib

unread,
Oct 26, 2020, 7:16:52 AM10/26/20
to django...@googlegroups.com
Your view must return a Jason response and not render a html file.

You should learn Django Rest Framework for that
This is an example here for how your view will look like:
API View


Omkar Parab

unread,
Oct 26, 2020, 7:47:48 AM10/26/20
to django...@googlegroups.com
In Trmplates 👇
os.path.join(BASE_DIR, 'new/build')

At the bottom 👇
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'new/build/static')    
]

On Mon, Oct 26, 2020, 3:24 PM Vineeth <vinee...@gmail.com> wrote:
I am using django 3.1 version how to connect django and react  i am trying to connect but 
getting Error like TemplateDoesNotExist at /index.html  i attached my folder structure and error image

--

David Nugent

unread,
Oct 26, 2020, 8:08:32 PM10/26/20
to django...@googlegroups.com, vinee...@gmail.com
In this situation, something you might also consider is FastAPI https://fastapi.tiangolo.com (which is based on Starlette https://www.starlette.io).

For the database you'll probably need to use SqlAlchemy vs Django ORM, but if you're serving static content and just need to provide an API it is definitely a leaner and more performant approach for supporting frontend applications.

If you are using templates at all, then there's either FastAPI+Jinja2, or Django+DRF as recommended by others.

I've had this choice a couple of times, and while sqlalchemy is ok, I always miss having Django's ORM which does a lot of work auto-magically - sqlalchemy being somewhat more explicit. FastAPI is pretty cool though, especially having redoc/openapi support out of the box with no additional requirements.

If you stay with Django, note that you aren't actually required to use DRF and have to tackle yet another complex framework. Most of the class based views assume HTMLResponse, but if you avoid using those - and TemplateView and subclasses in particular - you can explicitly return JsonResponse in your views instead.


Алмаз Есеньязов

unread,
Oct 27, 2020, 9:28:44 AM10/27/20
to django...@googlegroups.com
You need to write
BASE_DIR / 'build'
not
'/build/' 

пн, 26 окт. 2020 г., 15:55 Vineeth <vinee...@gmail.com>:
I am using django 3.1 version how to connect django and react  i am trying to connect but 
getting Error like TemplateDoesNotExist at /index.html  i attached my folder structure and error image

--

Ravi G

unread,
Nov 2, 2020, 12:10:15 PM11/2/20
to django...@googlegroups.com
Hi,

How to move source code to production if code consists of images
If anyone has any document related to  production . please share me

Reply all
Reply to author
Forward
0 new messages