├── api
├── __init__.py
├── migrations
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-38.pyc
│ │ └── 0001_initial.cpython-38.pyc
│ └── 0001_initial.py
├── tests.py
├── admin.py
├── apps.py
├── __pycache__
│ ├── urls.cpython-38.pyc
│ ├── admin.cpython-38.pyc
│ ├── models.cpython-38.pyc
│ ├── views.cpython-38.pyc
│ ├── __init__.cpython-38.pyc
│ └── serializers.cpython-38.pyc
├── models.py
├── urls.py
├── serializers.py
└── views.py
├── dictionary
├── __init__.py
├── __pycache__
│ ├── urls.cpython-38.pyc
│ ├── wsgi.cpython-38.pyc
│ ├── __init__.cpython-38.pyc
│ └── settings.cpython-38.pyc
├── asgi.py
├── wsgi.py
├── urls.py
└── settings.py
├── README.md
├── dictionary_react
├── src
│ ├── App.css
│ ├── setupTests.js
│ ├── App.test.js
│ ├── components
│ │ ├── Display.js
│ │ ├── Search.js
│ │ └── WordList.js
│ ├── index.css
│ ├── index.js
│ ├── App.js
│ └── serviceWorker.js
├── public
│ ├── robots.txt
│ ├── favicon.ico
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── index.html
└── package.json
├── db.sqlite3
├── .gitignore
└── manage.py
/api/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dictionary/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/api/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dictionary_django_rest_framework_with_react
--------------------------------------------------------------------------------
/api/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/dictionary_react/src/App.css:
--------------------------------------------------------------------------------
1 | .display{
2 | background-color: #b2beb5;
3 | height: 500px;
4 | }
5 |
--------------------------------------------------------------------------------
/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/db.sqlite3
--------------------------------------------------------------------------------
/api/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from .models import Word
3 |
4 | admin.site.register(Word)
5 |
--------------------------------------------------------------------------------
/api/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class ApiConfig(AppConfig):
5 | name = 'api'
6 |
--------------------------------------------------------------------------------
/dictionary_react/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/api/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/dictionary_react/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary_react/public/favicon.ico
--------------------------------------------------------------------------------
/dictionary_react/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary_react/public/logo192.png
--------------------------------------------------------------------------------
/dictionary_react/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary_react/public/logo512.png
--------------------------------------------------------------------------------
/api/__pycache__/admin.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/__pycache__/admin.cpython-38.pyc
--------------------------------------------------------------------------------
/api/__pycache__/models.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/__pycache__/models.cpython-38.pyc
--------------------------------------------------------------------------------
/api/__pycache__/views.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/__pycache__/views.cpython-38.pyc
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # dependencies
2 | dictionary_react/node_modules
3 | dictionary_react/.pnp
4 | dictionary_react/.pnp.js
5 |
6 | # production
7 | dictionary_react/build
8 |
--------------------------------------------------------------------------------
/api/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/api/__pycache__/serializers.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/__pycache__/serializers.cpython-38.pyc
--------------------------------------------------------------------------------
/dictionary/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/dictionary/__pycache__/wsgi.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary/__pycache__/wsgi.cpython-38.pyc
--------------------------------------------------------------------------------
/dictionary/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/dictionary/__pycache__/settings.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/dictionary/__pycache__/settings.cpython-38.pyc
--------------------------------------------------------------------------------
/api/migrations/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/migrations/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/api/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | class Word(models.Model):
4 | title = models.CharField(max_length=200)
5 |
6 | def __str__(self):
7 | return self.title
8 |
--------------------------------------------------------------------------------
/api/migrations/__pycache__/0001_initial.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/dictionary_django_rest_framework_with_react/HEAD/api/migrations/__pycache__/0001_initial.cpython-38.pyc
--------------------------------------------------------------------------------
/api/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from .import views
3 |
4 | urlpatterns = [
5 | path('', views.index, name='index'),
6 | path('word-list/', views.wordList, name='word-list'),
7 | ]
8 |
--------------------------------------------------------------------------------
/api/serializers.py:
--------------------------------------------------------------------------------
1 | from rest_framework import serializers
2 | from .models import Word
3 |
4 | class WordSerializer(serializers.ModelSerializer):
5 | class Meta:
6 | model = Word
7 | fields = '__all__'
8 |
--------------------------------------------------------------------------------
/dictionary_react/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom/extend-expect';
6 |
--------------------------------------------------------------------------------
/dictionary_react/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | const { getByText } = render();
7 | const linkElement = getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/dictionary_react/src/components/Display.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class Display extends React.Component {
4 |
5 | render(){
6 | // const words = this.props.words;
7 | return (
8 |
9 | Word meanings...
10 |
11 | );
12 | }
13 | }
14 |
15 | export default Display;
16 |
--------------------------------------------------------------------------------
/dictionary_react/src/components/Search.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class Search extends React.Component {
4 |
5 | render(){
6 | return (
7 |
8 | this.props.searchWord(e)} type="text" className="form-control" placeholder="words..." />
9 |
10 | );
11 | }
12 | }
13 |
14 | export default Search;
15 |
--------------------------------------------------------------------------------
/dictionary_react/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/dictionary/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for dictionary project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dictionary.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/dictionary/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for dictionary project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dictionary.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/dictionary_react/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want your app to work offline and load faster, you can change
15 | // unregister() to register() below. Note this comes with some pitfalls.
16 | // Learn more about service workers: https://bit.ly/CRA-PWA
17 | serviceWorker.unregister();
18 |
--------------------------------------------------------------------------------
/api/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.0.3 on 2020-09-02 19:47
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Word',
16 | fields=[
17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('title', models.CharField(max_length=200)),
19 | ],
20 | ),
21 | ]
22 |
--------------------------------------------------------------------------------
/api/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render
2 | from django.http import JsonResponse
3 | from rest_framework.decorators import api_view
4 | from rest_framework.response import Response
5 | from .serializers import WordSerializer
6 | from .models import Word
7 |
8 | @api_view(['GET'])
9 | def index(request):
10 | api_urls = {
11 | 'List':'/word-list/',
12 | 'Create':'/test-create/',
13 | }
14 | return Response(api_urls)
15 |
16 | @api_view(['GET'])
17 | def wordList(request):
18 | words = Word.objects.all().order_by('title')
19 | serializer = WordSerializer(words, many=True)
20 | return Response(serializer.data)
21 |
--------------------------------------------------------------------------------
/dictionary_react/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dictionary.settings')
9 | try:
10 | from django.core.management import execute_from_command_line
11 | except ImportError as exc:
12 | raise ImportError(
13 | "Couldn't import Django. Are you sure it's installed and "
14 | "available on your PYTHONPATH environment variable? Did you "
15 | "forget to activate a virtual environment?"
16 | ) from exc
17 | execute_from_command_line(sys.argv)
18 |
19 |
20 | if __name__ == '__main__':
21 | main()
22 |
--------------------------------------------------------------------------------
/dictionary_react/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "dictionary_react",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.5.0",
8 | "@testing-library/user-event": "^7.2.1",
9 | "react": "^16.13.1",
10 | "react-dom": "^16.13.1",
11 | "react-scripts": "3.4.3"
12 | },
13 | "scripts": {
14 | "start": "react-scripts start",
15 | "build": "react-scripts build",
16 | "test": "react-scripts test",
17 | "eject": "react-scripts eject"
18 | },
19 | "eslintConfig": {
20 | "extends": "react-app"
21 | },
22 | "browserslist": {
23 | "production": [
24 | ">0.2%",
25 | "not dead",
26 | "not op_mini all"
27 | ],
28 | "development": [
29 | "last 1 chrome version",
30 | "last 1 firefox version",
31 | "last 1 safari version"
32 | ]
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/dictionary_react/src/components/WordList.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class WordList extends React.Component {
4 |
5 | render(){
6 | const words = this.props.words;
7 | const search = this.props.search;
8 | const filteredWords = words.filter((word) => {
9 | return word.title.toLowerCase().indexOf(search.toLowerCase()) !== -1;
10 | });
11 | // const filteredWords = words.filter((word)=>{
12 | // if(search == null)
13 | // return word
14 | // else if(word.title.toLowerCase().includes(search.toLowerCase())){
15 | // return word
16 | // }
17 | // });
18 | return (
19 |
20 | {filteredWords.map(function(word, index){
21 | return(
22 | - {word.title}
23 | )
24 | })}
25 |
26 | );
27 | }
28 | }
29 |
30 | export default WordList;
31 |
--------------------------------------------------------------------------------
/dictionary/urls.py:
--------------------------------------------------------------------------------
1 | """dictionary URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path, include
18 | from django.views.generic import TemplateView
19 |
20 | urlpatterns = [
21 | path('', TemplateView.as_view(template_name='index.html')),
22 | path('admin/', admin.site.urls),
23 | path('api/', include('api.urls'))
24 | ]
25 |
--------------------------------------------------------------------------------
/dictionary_react/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
18 |
19 |
28 | Dictionary
29 |
30 |
31 |
32 |
33 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/dictionary_react/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import WordList from './components/WordList';
3 | import Search from './components/Search';
4 | import Display from './components/Display';
5 | import './App.css';
6 |
7 | class App extends React.Component {
8 | constructor(props){
9 | super(props);
10 | this.state = {
11 | wordList: [],
12 | // search: null,
13 | search: '',
14 | }
15 | this.fetchWords = this.fetchWords.bind(this)
16 | this.searchWord = this.searchWord.bind(this)
17 | this.displayDetails = this.displayDetails.bind(this)
18 | }
19 |
20 | componentDidMount(){
21 | this.fetchWords();
22 | this.displayDetails();
23 | }
24 |
25 | fetchWords(){
26 | console.log('Fetching words list...');
27 | fetch('http://127.0.0.1:8000/api/word-list/')
28 | .then(response => response.json())
29 | .then(data =>
30 | // console.log('Test List', data)
31 | this.setState({
32 | wordList: data,
33 | }, console.log('word list: ', this.state.wordList))
34 | );
35 | }
36 |
37 | displayDetails(){
38 | // let [first] = Object.keys(ahash);
39 | // console.log(this.state.wordList);
40 | let d = this.state.wordList;
41 | let firstKey = Object.keys(this.state.wordList)[0];
42 | console.log(Object.keys(d));
43 | console.log(firstKey);
44 | }
45 |
46 | searchWord=(event)=>{
47 | let keyword = event.target.value;
48 | console.log('before set: ', keyword);
49 | this.setState({search: keyword}, console.log('after set: ', this.state.search));
50 | // console.log('searching...');
51 | console.log(this.state.search);
52 | }
53 |
54 | render(){
55 | var words = this.state.wordList;
56 | var search = this.state.search;
57 | return (
58 |
59 |
60 |
61 |
Dictionary
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | );
75 | }
76 | }
77 |
78 | export default App;
79 |
--------------------------------------------------------------------------------
/dictionary/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for dictionary project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.0.7.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.0/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.0/ref/settings/
11 | """
12 |
13 | import os
14 |
15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 | REACT_TEMP_DIR = os.path.join(BASE_DIR, 'dictionary_react/build')
18 | REACT_STATIC_DIR = os.path.join(BASE_DIR, 'dictionary_react/build/static')
19 |
20 |
21 | # Quick-start development settings - unsuitable for production
22 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
23 |
24 | # SECURITY WARNING: keep the secret key used in production secret!
25 | SECRET_KEY = 'd6!me=2rs)$*f#34jtv^%*g7fwk9-jw*f&wb22rn2i1eb5=am!'
26 |
27 | # SECURITY WARNING: don't run with debug turned on in production!
28 | DEBUG = True
29 |
30 | ALLOWED_HOSTS = []
31 |
32 |
33 | # Application definition
34 |
35 | INSTALLED_APPS = [
36 | 'django.contrib.admin',
37 | 'django.contrib.auth',
38 | 'django.contrib.contenttypes',
39 | 'django.contrib.sessions',
40 | 'django.contrib.messages',
41 | 'django.contrib.staticfiles',
42 | 'api',
43 | 'rest_framework',
44 | 'corsheaders',
45 | ]
46 |
47 | MIDDLEWARE = [
48 | 'corsheaders.middleware.CorsMiddleware',
49 | 'django.middleware.security.SecurityMiddleware',
50 | 'django.contrib.sessions.middleware.SessionMiddleware',
51 | 'django.middleware.common.CommonMiddleware',
52 | 'django.middleware.csrf.CsrfViewMiddleware',
53 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
54 | 'django.contrib.messages.middleware.MessageMiddleware',
55 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
56 | ]
57 |
58 | ROOT_URLCONF = 'dictionary.urls'
59 |
60 | TEMPLATES = [
61 | {
62 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
63 | 'DIRS': [
64 | REACT_TEMP_DIR,
65 | ],
66 | 'APP_DIRS': True,
67 | 'OPTIONS': {
68 | 'context_processors': [
69 | 'django.template.context_processors.debug',
70 | 'django.template.context_processors.request',
71 | 'django.contrib.auth.context_processors.auth',
72 | 'django.contrib.messages.context_processors.messages',
73 | ],
74 | },
75 | },
76 | ]
77 |
78 | WSGI_APPLICATION = 'dictionary.wsgi.application'
79 |
80 |
81 | # Database
82 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
83 |
84 | DATABASES = {
85 | 'default': {
86 | 'ENGINE': 'django.db.backends.sqlite3',
87 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
88 | }
89 | }
90 |
91 |
92 | # Password validation
93 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
94 |
95 | AUTH_PASSWORD_VALIDATORS = [
96 | {
97 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
98 | },
99 | {
100 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
101 | },
102 | {
103 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
104 | },
105 | {
106 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
107 | },
108 | ]
109 |
110 |
111 | # Internationalization
112 | # https://docs.djangoproject.com/en/3.0/topics/i18n/
113 |
114 | LANGUAGE_CODE = 'en-us'
115 |
116 | TIME_ZONE = 'UTC'
117 |
118 | USE_I18N = True
119 |
120 | USE_L10N = True
121 |
122 | USE_TZ = True
123 |
124 |
125 | # Static files (CSS, JavaScript, Images)
126 | # https://docs.djangoproject.com/en/3.0/howto/static-files/
127 |
128 | STATIC_URL = '/static/'
129 |
130 | STATICFILES_DIRS = [
131 | REACT_STATIC_DIR,
132 | ]
133 |
134 | CORS_ORIGIN_WHITELIST = [
135 | "http://localhost:3000",
136 | ]
137 |
--------------------------------------------------------------------------------
/dictionary_react/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------