Уже 24 часа и до сих пор не могу понять, шаблон не отображается, когда я просматриваю 127.0.0.1:8000 или localhost: 8000 в моем браузере.Я настроил это с реакцией JS, так как мой интерфейс, пожалуйста, посмотрите мой путь на картинке.Я печатаю в своих представлениях, и он отображается в моем терминале, но в браузере я не вижу свой шаблон, только пустую страницу.
мой путь: ![enter image description here](https://i.stack.imgur.com/IMviB.png)
settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
'webpack_loader',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ os.path.join(BASE_DIR, "templates") ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'bundles/', # end with slash
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-local.json'),
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
}
}
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app/static'),
]
urls.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('app.urls')),
]
** URL.py ** внутри папки приложения
from django.conf.urls import url, include
from .views import *
urlpatterns = [
url(r'^$', homePage, name = 'home_page'),
]
views.py
from django.shortcuts import render
def homePage(request): # landing page
context = {}
template = 'base.html'
print('testing terminal') #this line in termninal is printing when I am opening 127.0.0.1:8000 / localhost:8000
return render( request, template, context )
base.html
{% load render_bundle from webpack_loader %}
<!DOCTYPE html>
<html lang="en">
<head>
{% load staticfiles %}
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Reactjs with MobX</title>
<link rel="stylesheet" href="{% static 'font-awesome-4.7.0/css/font-awesome.min.css' %}">
<link rel="stylesheet" href="{% static 'iconmoon/style.css' %}">
<!-- <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}"> -->
<!-- <link rel="stylesheet" href="{% static 'muicss/mui.css' %}"> -->
</head>
<body>
{% csrf_token %}
<div id="main-content"></div>
{% render_bundle 'main' %}
</body>
</div>
</html>
webpack.base.config.js
var path = require("path")
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')
// new WebpackDevServer(webpack(config), {
module.exports = {
context: __dirname,
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./app/modules/common/index'
],
// 'webpack-dev-server/client?http://localhost:3000',
// 'webpack/hot/only-dev-server',
// './app/modules/common/index',
output: {
path: path.resolve('./app/static/bundles/'),
filename: '[name]-[hash].js',
publicPath: 'http://localhost:3000/app/static/bundles/',
// Tell django to use this URL to load packages and not use STATIC_URL + bundle_name
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(), // don't reload if there is an error
new BundleTracker({filename: './webpack-stats.json'}),
// new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
],
module: {
loaders: [
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.(jpe?g|png|gif|svg)$/i, loader: "file-loader?name=public/icons/[name].[ext]"},
// working her
// {
// test: /\.(js|jsx)$/,
// loader: 'babel-loader',
// exclude: /node_modules/,
// query: {
// presets: [
// '@babel/env',
// '@babel/react',
// ],
// }
// },
{ test: /\.(js|jsx)$/, exclude: /node_modules/,
loaders: ['react-hot-loader/webpack', 'babel?' + JSON.stringify(
{
presets: ['react', 'es2015','stage-0'],
plugins: ["transform-decorators-legacy"]
})]
},
],
},
resolve: {
modulesDirectories: ['node_modules', 'bower_components'],
extensions: ['', '.js', '.jsx']
}
}