├── .gitignore
├── LICENSE
├── README.md
├── assets
└── client
│ └── src
│ ├── components
│ ├── App.js
│ ├── App.less
│ ├── about
│ │ └── AboutPage.js
│ ├── footer
│ │ └── Footer.js
│ ├── header
│ │ └── header.js
│ ├── home
│ │ └── HomePage.js
│ ├── login-select
│ │ ├── LoginSelect.js
│ │ └── LoginSelect.less
│ └── main
│ │ └── Main.js
│ ├── index.js
│ └── vendor
│ └── bootswatch-flatly.css
├── manage.py
├── myapp
├── __init__.py
├── admin.py
├── apps.py
├── migrations
│ └── __init__.py
├── models.py
├── templates
│ └── myapp
│ │ ├── index.html
│ │ └── test.html
├── tests.py
├── urls.py
└── views.py
├── package-lock.json
├── package.json
├── react_webpack_django
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
├── requirements.txt
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
3 | # Django / React / Webpack stuff
4 | venv/*
5 | db.sqlite3
6 | *.pyc
7 | webpack-stats.json
8 | assets/bundles
9 |
10 | # Logs
11 | logs
12 | *.log
13 | npm-debug.log*
14 | yarn-debug.log*
15 | yarn-error.log*
16 |
17 | # Runtime data
18 | pids
19 | *.pid
20 | *.seed
21 | *.pid.lock
22 |
23 | # Directory for instrumented libs generated by jscoverage/JSCover
24 | lib-cov
25 |
26 | # Coverage directory used by tools like istanbul
27 | coverage
28 |
29 | # nyc test coverage
30 | .nyc_output
31 |
32 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
33 | .grunt
34 |
35 | # Bower dependency directory (https://bower.io/)
36 | bower_components
37 |
38 | # node-waf configuration
39 | .lock-wscript
40 |
41 | # Compiled binary addons (http://nodejs.org/api/addons.html)
42 | build/Release
43 |
44 | # Dependency directories
45 | node_modules/
46 | jspm_packages/
47 |
48 | # Typescript v1 declaration files
49 | typings/
50 |
51 | # Optional npm cache directory
52 | .npm
53 |
54 | # Optional eslint cache
55 | .eslintcache
56 |
57 | # Optional REPL history
58 | .node_repl_history
59 |
60 | # Output of 'npm pack'
61 | *.tgz
62 |
63 | # Yarn Integrity file
64 | .yarn-integrity
65 |
66 | # dotenv environment variables file
67 | .env
68 |
69 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Dan Wild
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-webpack-django
2 |
3 | Full-stack application scaffold.
4 | Structured to provide [much needed decoupling](http://owaislone.org/blog/modern-frontends-with-django/) between the
5 | client application build and Django's opinionated pipeline/staticfiles systems.
6 |
7 | Achieved by using [webpack](https://webpack.js.org/) to manage our client bundling, with these tools:
8 | * [webpack-bundle-tracker](https://github.com/owais/webpack-bundle-tracker)
9 | * [django-webpack-loader](https://github.com/owais/django-webpack-loader/)
10 |
11 | In short, we'll let Django do what it is good at; Server-side/ORM stuff, while de-coupling the client for greater flexibility (and less confusing black-box Django magic!)
12 |
13 | ## routing notes
14 | * Routing (e.g. `/`, `/about`) has been configured using `react-router-dom`.
15 | * In our Django apps `urls.py` we have defined a catchall which essentially defers routing to React.
16 | * There is also an example url configured to allow django to serve a route template (depending on your use case you may want a mix of both approaches).
17 |
18 | ## styling
19 | * Bootstrap v4 Alpha with [reactstrap](https://reactstrap.github.io/) for UI components has been added
20 | * [less-loader](https://github.com/webpack-contrib/less-loader) has been configured to transpile/bundle less files.
21 | * Uses [Bootswatch Flatly 4 Alpha](https://bootswatch.com/4-alpha/flatly/) theme
22 | * Uses [react-fa](https://github.com/andreypopp/react-fa) for FontAwesome icons as React components.
23 |
24 | ## todo
25 | * Client/Server request auth.
26 |
27 | ## install, build, run etc.
28 |
29 | From project root:
30 | ```shell
31 | # javascript things
32 | npm install # install js packages
33 | npm run watch # run webpack build for client app, and rebuild on \*change
34 |
35 | # python things
36 | virtualenv venv # create python virtualenv
37 | source venv/bin/activate # enter venv
38 | pip install -r requirements.txt # install pip packages
39 | python manage.py runserver # serve
40 | ```
41 |
42 | \*to just build a webpack bundle once use: `npm run build`
43 |
44 | ## License
45 | MIT License
46 |
47 | ## Resources
48 | Heavily based on these great resources:
49 | * [Let's modernize the way we handle frontend code with Django](http://owaislone.org/blog/modern-frontends-with-django/)
50 | * [Using Webpack transparently with Django + hot reloading React components as a bonus](http://owaislone.org/blog/webpack-plus-reactjs-and-django/)
51 | * [Using React with Django, with a little help from Webpack](http://geezhawk.github.io/using-react-with-django-rest-framework)
52 | * [Setting up ReactJS/Redux using Webpack for an existing Django project](https://gist.github.com/genomics-geek/81c6880ca862d99574c6f84dec81acb0)
53 | * [Moving to Webpack v2](https://javascriptplayground.com/blog/2016/10/moving-to-webpack-2/) (notes still useful, many example use v1)
54 |
55 |
--------------------------------------------------------------------------------
/assets/client/src/components/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 |
4 | import Header from './header/Header';
5 | import Main from './main/Main';
6 | import Footer from './footer/Footer';
7 |
8 | export default class App extends React.Component {
9 | render(){
10 | return (
11 |
12 |
13 |
14 |
15 |
16 | );
17 | }
18 | }
--------------------------------------------------------------------------------
/assets/client/src/components/App.less:
--------------------------------------------------------------------------------
1 | // bootstrap 4
2 | @import '~bootstrap/dist/css/bootstrap.css';
3 |
4 | // our theme
5 | // https://bootswatch.com/4-alpha/flatly/
6 | @import '../vendor/bootswatch-flatly.css';
7 |
8 | // component styles
9 | @import './login-select/LoginSelect';
10 |
11 |
12 | //@import '~font-awesome/less/font-awesome.less';
--------------------------------------------------------------------------------
/assets/client/src/components/about/AboutPage.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import '../App.less';
3 | import { UncontrolledAlert } from 'reactstrap';
4 |
5 | export default class About extends React.Component {
6 | render(){
7 | return (
8 |
9 |
About page
10 |
11 | I am an alert and I can be dismissed!
12 |
13 |
14 | );
15 | }
16 | }
--------------------------------------------------------------------------------
/assets/client/src/components/footer/Footer.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default class Footer extends React.Component {
4 |
5 | render() {
6 | return (
7 |
10 | )
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/assets/client/src/components/header/header.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'react-router-dom';
3 |
4 | import { Collapse, Navbar, NavbarToggler, NavbarBrand, Nav, NavItem, NavLink } from 'reactstrap';
5 |
6 | import HomePage from '../home/HomePage';
7 | import AboutPage from '../about/AboutPage';
8 | import LoginSelect from '../login-select/LoginSelect';
9 |
10 | export default class Header extends React.Component {
11 |
12 | constructor(props) {
13 | super(props);
14 |
15 | this.toggle = this.toggle.bind(this);
16 | this.state = {
17 | isOpen: false
18 | };
19 | }
20 | toggle() {
21 | this.setState({
22 | isOpen: !this.state.isOpen
23 | });
24 | }
25 | render() {
26 | return (
27 |
28 |
29 |
49 |
50 |
51 | //
52 | //
53 | //
54 | // MyApp
55 | //
56 | //
64 | //
65 | //
66 | //
67 | );
68 | }
69 |
70 | //render() {
71 | // return (
72 | //
73 | //
74 | //
80 | //
81 | //
82 | // )
83 | //}
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/assets/client/src/components/home/HomePage.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Alert } from 'reactstrap';
3 | import {Icon} from 'react-fa'
4 | import '../App.less';
5 |
6 | export default class Home extends React.Component {
7 | render(){
8 | return (
9 |
10 |
Home Page
11 |
12 | Whoooah! We successfully react-strapped this UI's arse!
13 | And; here's a spinning icon:
14 |
15 |
16 | );
17 | }
18 | }
--------------------------------------------------------------------------------
/assets/client/src/components/login-select/LoginSelect.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { ButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
3 | import {Icon} from 'react-fa'
4 |
5 | export default class LoginSelect extends React.Component {
6 | constructor(props) {
7 | super(props);
8 |
9 | this.toggle = this.toggle.bind(this);
10 | this.state = {
11 | dropdownOpen: false
12 | };
13 | }
14 |
15 | toggle() {
16 | this.setState({
17 | dropdownOpen: !this.state.dropdownOpen
18 | });
19 | }
20 |
21 | render() {
22 | return (
23 |
24 | Logged in as:
25 |
26 |
27 | danwild@y7mail.com
28 |
29 |
30 | Settings
31 |
32 | Logout
33 |
34 |
35 |
36 | );
37 | }
38 | }
--------------------------------------------------------------------------------
/assets/client/src/components/login-select/LoginSelect.less:
--------------------------------------------------------------------------------
1 | .LoginSelect {
2 |
3 | color: #fff;
4 |
5 | .label {
6 | padding-right: 10px;
7 | }
8 |
9 | }
--------------------------------------------------------------------------------
/assets/client/src/components/main/Main.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Switch, Route } from 'react-router-dom';
3 | import HomePage from '../home/HomePage';
4 | import AboutPage from '../about/AboutPage';
5 |
6 | export default class Main extends React.Component {
7 |
8 | render() {
9 | return (
10 |
11 |
12 |
13 |
14 |
15 |
16 | )
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/assets/client/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import { BrowserRouter } from 'react-router-dom';
4 |
5 | //require("font-awesome-webpack");
6 |
7 | //require('font-awesome/css/font-awesome.css');
8 |
9 | import App from './components/App';
10 |
11 | ReactDOM.render((
12 |
13 |
14 |
15 | ), document.getElementById('react-app'));
16 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "react_webpack_django.settings")
7 | try:
8 | from django.core.management import execute_from_command_line
9 | except ImportError:
10 | # The above import may fail for some other reason. Ensure that the
11 | # issue is really that Django is missing to avoid masking other
12 | # exceptions on Python 2.
13 | try:
14 | import django
15 | except ImportError:
16 | raise ImportError(
17 | "Couldn't import Django. Are you sure it's installed and "
18 | "available on your PYTHONPATH environment variable? Did you "
19 | "forget to activate a virtual environment?"
20 | )
21 | raise
22 | execute_from_command_line(sys.argv)
23 |
--------------------------------------------------------------------------------
/myapp/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danwild/react-webpack-django/51b806b7336588aac2f9a973cc5f0fb4934a4680/myapp/__init__.py
--------------------------------------------------------------------------------
/myapp/admin.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.contrib import admin
5 |
6 | # Register your models here.
7 |
--------------------------------------------------------------------------------
/myapp/apps.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.apps import AppConfig
5 |
6 |
7 | class MyappConfig(AppConfig):
8 | name = 'myapp'
9 |
--------------------------------------------------------------------------------
/myapp/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danwild/react-webpack-django/51b806b7336588aac2f9a973cc5f0fb4934a4680/myapp/migrations/__init__.py
--------------------------------------------------------------------------------
/myapp/models.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models
5 |
6 | # Create your models here.
7 |
--------------------------------------------------------------------------------
/myapp/templates/myapp/index.html:
--------------------------------------------------------------------------------
1 | {% load render_bundle from webpack_loader %}
2 |
3 |
4 |
5 |
6 | Example
7 |
8 |
9 |
10 |
11 | {% render_bundle 'main' %}
12 |
13 |
--------------------------------------------------------------------------------
/myapp/templates/myapp/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | A Static Test Page
9 |
10 |
--------------------------------------------------------------------------------
/myapp/tests.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.test import TestCase
5 |
6 | # Create your tests here.
7 |
--------------------------------------------------------------------------------
/myapp/urls.py:
--------------------------------------------------------------------------------
1 | from django.conf.urls import url
2 | from . import views
3 |
4 | urlpatterns = [
5 |
6 | # match all pages to our index so React can handle routing
7 | url(r'^(?:.*)/?$', views.index),
8 |
9 | # how you might explicitly define route
10 | # url(r'^$', views.index, name='index'),
11 |
12 | # example of how to static template from django just for fun
13 | url(r'^test/', views.test, name='test'),
14 | ]
--------------------------------------------------------------------------------
/myapp/views.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.shortcuts import render
5 |
6 | # Create your views here.
7 | from django.http import HttpResponse
8 | from django.template import loader
9 |
10 |
11 | def index(request):
12 | template = loader.get_template('myapp/index.html')
13 | context = {
14 | 'foo': 'bar',
15 | }
16 | return HttpResponse(template.render(context, request))
17 |
18 | def test(request):
19 | template = loader.get_template('myapp/test.html')
20 | context = {
21 | 'foo': 'bar',
22 | }
23 | return HttpResponse(template.render(context, request))
24 | # return HttpResponse("Hello, world. You're at the TEST.")
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-webpack-django",
3 | "version": "0.0.1",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "build": "./node_modules/.bin/webpack --config webpack.config.js",
9 | "watch": "./node_modules/.bin/webpack --config webpack.config.js --watch"
10 | },
11 | "repository": {
12 | "type": "git",
13 | "url": "git+https://github.com/danwild/react-webpack-django.git"
14 | },
15 | "author": "",
16 | "license": "MIT",
17 | "bugs": {
18 | "url": "https://github.com/danwild/react-webpack-django/issues"
19 | },
20 | "homepage": "https://github.com/danwild/react-webpack-django#readme",
21 | "devDependencies": {
22 | "babel": "^6.23.0",
23 | "babel-core": "^6.25.0",
24 | "babel-loader": "^7.1.1",
25 | "babel-preset-env": "^1.6.0",
26 | "babel-preset-es2015": "^6.24.1",
27 | "babel-preset-react": "^6.24.1",
28 | "bootstrap": "^4.0.0-beta",
29 | "css-loader": "^0.28.4",
30 | "extract-text-webpack-plugin": "^3.0.0",
31 | "file-loader": "^0.11.2",
32 | "font-awesome": "^4.7.0",
33 | "less": "^2.7.2",
34 | "less-loader": "^4.0.5",
35 | "react": "^15.6.1",
36 | "react-addons-css-transition-group": "^15.6.0",
37 | "react-addons-transition-group": "^15.6.0",
38 | "react-dom": "^15.6.1",
39 | "react-router-dom": "^4.1.2",
40 | "reactstrap": "^4.8.0",
41 | "style-loader": "^0.18.2",
42 | "url-loader": "^0.5.9",
43 | "webpack": "^3.5.4",
44 | "webpack-bundle-tracker": "^0.3.0"
45 | },
46 | "dependencies": {
47 | "react-fa": "^5.0.0"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/react_webpack_django/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danwild/react-webpack-django/51b806b7336588aac2f9a973cc5f0fb4934a4680/react_webpack_django/__init__.py
--------------------------------------------------------------------------------
/react_webpack_django/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for restyReactDjango project.
3 |
4 | Generated by 'django-admin startproject' using Django 1.11.4.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/1.11/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/1.11/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 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = '$0#$yx7p)8ab!#47n_ri#kx1n=__vj$zxb#u2de*u2w%^$$7v&'
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 | STATICFILES_DIRS = (
31 | os.path.join(BASE_DIR, 'assets'), # We do this so that django's collectstatic copies or our bundles to the STATIC_ROOT or syncs them to whatever storage we use.
32 | )
33 |
34 | WEBPACK_LOADER = {
35 | 'DEFAULT': {
36 | 'BUNDLE_DIR_NAME': 'bundles/',
37 | 'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
38 | }
39 | }
40 |
41 | # Application definition
42 |
43 | INSTALLED_APPS = [
44 | 'webpack_loader',
45 | 'myapp',
46 | 'django.contrib.admin',
47 | 'django.contrib.auth',
48 | 'django.contrib.contenttypes',
49 | 'django.contrib.sessions',
50 | 'django.contrib.messages',
51 | 'django.contrib.staticfiles',
52 | ]
53 |
54 | MIDDLEWARE = [
55 | 'django.middleware.security.SecurityMiddleware',
56 | 'django.contrib.sessions.middleware.SessionMiddleware',
57 | 'django.middleware.common.CommonMiddleware',
58 | 'django.middleware.csrf.CsrfViewMiddleware',
59 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
60 | 'django.contrib.messages.middleware.MessageMiddleware',
61 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
62 | ]
63 |
64 | ROOT_URLCONF = 'react_webpack_django.urls'
65 |
66 | TEMPLATES = [
67 | {
68 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
69 | 'DIRS': [],
70 | 'APP_DIRS': True,
71 | 'OPTIONS': {
72 | 'context_processors': [
73 | 'django.template.context_processors.debug',
74 | 'django.template.context_processors.request',
75 | 'django.contrib.auth.context_processors.auth',
76 | 'django.contrib.messages.context_processors.messages',
77 | ],
78 | },
79 | },
80 | ]
81 |
82 | WSGI_APPLICATION = 'react_webpack_django.wsgi.application'
83 |
84 |
85 | # Database
86 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
87 |
88 | DATABASES = {
89 | 'default': {
90 | 'ENGINE': 'django.db.backends.sqlite3',
91 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
92 | }
93 | }
94 |
95 |
96 | # Password validation
97 | # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
98 |
99 | AUTH_PASSWORD_VALIDATORS = [
100 | {
101 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
102 | },
103 | {
104 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
105 | },
106 | {
107 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
108 | },
109 | {
110 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
111 | },
112 | ]
113 |
114 |
115 | # Internationalization
116 | # https://docs.djangoproject.com/en/1.11/topics/i18n/
117 |
118 | LANGUAGE_CODE = 'en-us'
119 |
120 | TIME_ZONE = 'UTC'
121 |
122 | USE_I18N = True
123 |
124 | USE_L10N = True
125 |
126 | USE_TZ = True
127 |
128 |
129 | # Static files (CSS, JavaScript, Images)
130 | # https://docs.djangoproject.com/en/1.11/howto/static-files/
131 |
132 | STATIC_URL = '/static/'
133 |
--------------------------------------------------------------------------------
/react_webpack_django/urls.py:
--------------------------------------------------------------------------------
1 | """restyReactDjango URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/1.11/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: url(r'^$', 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: url(r'^$', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.conf.urls import url, include
14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15 | """
16 | from django.conf.urls import include, url
17 | from django.contrib import admin
18 |
19 | urlpatterns = [
20 |
21 | # all URLS being configured in myapp.urls
22 | url(r'^', include('myapp.urls')),
23 |
24 | # admin
25 | url(r'^admin/', admin.site.urls),
26 | ]
27 |
--------------------------------------------------------------------------------
/react_webpack_django/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for restyReactDjango 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/1.11/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", "react_webpack_django.settings")
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | Django==1.11.20
2 | django-webpack-loader==0.5.0
3 | pytz==2017.2
4 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require('webpack');
3 | const BundleTracker = require('webpack-bundle-tracker');
4 | const ExtractTextPlugin = require("extract-text-webpack-plugin");
5 |
6 | module.exports = {
7 | context: __dirname,
8 |
9 | entry: './assets/client/src/index.js', // entry point of our app.
10 |
11 | output: {
12 | path: path.resolve('./assets/bundles/'),
13 | filename: "[name]-[hash].js"
14 | },
15 |
16 | plugins: [
17 | new BundleTracker({
18 | filename: './webpack-stats.json'
19 | }),
20 | new ExtractTextPlugin("styles.css")
21 | ],
22 |
23 | module: {
24 | rules: [
25 | {
26 | test: /\.jsx?$/, // to transform JSX into JS
27 | exclude: /node_modules/,
28 | loader: 'babel-loader',
29 | query :{
30 | presets:['react','es2015']
31 | }
32 | },
33 | //{
34 | // test: /\.less?$/,
35 | // use: [{
36 | // loader: "style-loader"
37 | // }, {
38 | // loader: "css-loader"
39 | // }, {
40 | // loader: "less-loader", options: {
41 | // strictMath: true,
42 | // noIeCompat: true
43 | // }
44 | // }]
45 | //},
46 |
47 | {
48 | test: /\.less$/i,
49 | use: ExtractTextPlugin.extract(['css-loader', 'less-loader'])
50 | },
51 | {
52 | test: /\.css?$/,
53 | use: ExtractTextPlugin.extract({
54 | fallback: "style-loader",
55 | use: "css-loader"
56 | })
57 | },
58 | {
59 | test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
60 | loader: 'url-loader?limit=10000&mimetype=application/font-woff'
61 | },
62 | {
63 | test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
64 | loader: 'file-loader'
65 | },
66 |
67 | //{
68 | // test: /\.(eot|ttf|woff2?|otf|svg|png|jpg)$/,
69 | // loaders: ['file-loader']
70 | //},
71 | //{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
72 | //{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
73 |
74 | // font-awesome icons
75 | // the url-loader uses DataUrls.
76 | // the file-loader emits files.
77 | //{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
78 | //{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }
79 |
80 | //{
81 | // test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
82 | // loader: "url?limit=10000&mimetype=application/font-woff"
83 | //}, {
84 | // test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
85 | // loader: "url?limit=10000&mimetype=application/font-woff"
86 | //}, {
87 | // test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
88 | // loader: "url?limit=10000&mimetype=application/octet-stream"
89 | //}, {
90 | // test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
91 | // loader: "file"
92 | //}, {
93 | // test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
94 | // loader: "url?limit=10000&mimetype=image/svg+xml"
95 | //}
96 | //{ test: /\.(jpg|png|woff|woff2|eot|ttf|svg)$/, loader: 'file-loader?name=[path][name].[ext]?[hash]' },
97 | //{
98 | // test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
99 | // loader: 'url?limit=10000',
100 | //}
101 | ]
102 | },
103 |
104 | resolve: {
105 | modules: ['node_modules', 'bower_components'],
106 | extensions: ['.js', '.jsx']
107 | }
108 | };
--------------------------------------------------------------------------------