-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[add] #25 djangoからREST FrameWorkを取得出来るようにした フロント側でDBの情報を取得するため
- Loading branch information
1 parent
6a2fda9
commit 79d90b7
Showing
12 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from django.contrib import admin | ||
from .models import User | ||
|
||
# Register your models here. | ||
|
||
admin.site.register(User) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from rest_framework import serializers | ||
from .models import User | ||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ('id','name','age') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState , useEffect } from "react"; | ||
import axios from 'axios'; | ||
|
||
import messages from '../../json/Message.json' | ||
|
||
const Listget = ({url}) => { | ||
let fetched = false; | ||
let [jsonfetchDatas,FetchResponse] = useState([]) | ||
|
||
useEffect(() => { | ||
axios.get(url).then((res) => { | ||
FetchResponse(res.data); | ||
fetched = true; | ||
}); | ||
},[]); | ||
|
||
const Success = ({datas}) => { | ||
return ( | ||
<ul> | ||
{datas.map((data) => { | ||
return ( | ||
<li key={data.id}> | ||
<div> | ||
<span>id: {data.id}</span> | ||
</div> | ||
<div> | ||
<span>name: {data.name}</span> | ||
</div> | ||
<div> | ||
<span>age: {data.age}</span> | ||
</div> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
{!fetched && <div>{messages.Server.BackendFetchError["01"]}</div>} | ||
{ fetched && <Success datas={jsonfetchDatas}/> } | ||
</> | ||
); | ||
}; | ||
|
||
export default Listget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"Server": { | ||
"BackendFetchError": { | ||
"01": "バックエンドのサーバーを起動してください" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"datas": [ | ||
{ | ||
"data": 1, | ||
"id": 1 | ||
}, | ||
{ | ||
"data": 2, | ||
"id": 5 | ||
}, | ||
{ | ||
"data": 4, | ||
"id": 5 | ||
} | ||
] | ||
} |