-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme file.txt
53 lines (38 loc) · 916 Bytes
/
readme file.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Connect React js with django
Method 1)
Make a django project and make an virtual enviornment and activate that enviornment.
Install djangorestframework
INSTALLED_APPS = [
'rest_framework',
'frontend',
]
Create react app
npx create-react-app frontend
and run that npm run build
Settings.py
'DIRS': [os.path.join(BASE_DIR, '../frontend')],
STATICFILES_DIRS = [
os.path.join(BASE_DIR, '../frontend/build/static'),
]
python manage.py runserver
Method 2)
django-cors-headers
INSTALLED_APPS = [
'rest_framework',
'corsheaders', # new
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # new
'django.middleware.common.CommonMiddleware', # new
]
CORS_ORIGIN_WHITELIST = (
'localhost:3000/'
)
http-common.js
import axios from "axios";
export default axios.create({
baseURL: "http://localhost:8080/api",
headers: {
"Content-type": "application/json"
}
});