Skip to content

Commit 80d68df

Browse files
committed
Connecting django with react
1 parent 422a6e9 commit 80d68df

30 files changed

+58
-32
lines changed
Binary file not shown.
835 Bytes
Binary file not shown.

backend/backend/settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
TEMPLATES = [
6767
{
6868
'BACKEND': 'django.template.backends.django.DjangoTemplates',
69-
'DIRS': [],
69+
'DIRS': [
70+
BASE_DIR / 'frontend/build', # Path to React build directory
71+
],
7072
'APP_DIRS': True,
7173
'OPTIONS': {
7274
'context_processors': [
@@ -129,6 +131,10 @@
129131

130132
STATIC_URL = 'static/'
131133

134+
STATICFILES_DIRS = [
135+
BASE_DIR / 'frontend/build/static', # Path to React static files
136+
]
137+
132138
# Default primary key field type
133139
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
134140

backend/backend/urls.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
"""
2+
URL configuration for backend project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.0/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
117
from django.contrib import admin
218
from django.urls import path, include
19+
from django.views.generic import TemplateView
20+
321

422
urlpatterns = [
523
path('admin/', admin.site.urls),
6-
path('api/', include('api.urls')), # Adjusted to use single quotes consistently
24+
path("api/", include("api.urls")),
25+
path('', TemplateView.as_view(template_name='index.html')),
26+
727
]

backend/db.sqlite3

0 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

backend/frontend/src/App.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { HashRouter as Router, Routes, Route } from 'react-router-dom'; // Import HashRouter instead of BrowserRouter
3+
import PrivateRoute from './utils/PrivateRoutes';
4+
import { AuthProvider } from './context/AuthContext';
5+
6+
import Homepage from './views/Homepage';
7+
import Registerpage from './views/Registerpage';
8+
import Loginpage from './views/Loginpage';
9+
import Dashboard from './views/Dashboard';
10+
import Navbar from './views/Navbar';
11+
12+
function App() {
13+
return (
14+
<Router>
15+
<AuthProvider>
16+
<Navbar />
17+
<Routes>
18+
<Route path="/" element={<Homepage />} />
19+
<Route path="/login" element={<Loginpage />} />
20+
<Route path="/register" element={<Registerpage />} />
21+
<Route element={<PrivateRoute />}>
22+
<Route path="/dashboard" element={<Dashboard />} />
23+
</Route>
24+
</Routes>
25+
</AuthProvider>
26+
</Router>
27+
);
28+
}
29+
30+
export default App;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.

frontend/src/App.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)