javascript - React.Js 未在 django 项目中渲染

标签 javascript html django reactjs

我正在创建一个项目,其中 React 不会在 django localhost 上渲染任何内容

index.html

<!DOCTYPE html>
<html lang="en">
    <head></head>
    <body>
        <div id="App">
            <!---all will be define in App.js-->
            <h1>Index.html </h1>
        </div>
    </body>
    {% load static%}
    <script src="{% static "frontend/main.js" %}"></script>
</html>

app.js

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Header from './layout/header';

class App extends Component {
    render() {
        return (
        <h1>App.JS</h1>
        )
    }
}

ReactDOM.render(<App />, document.getElementById('app'));

这是我的项目结构:

Project structure

运行 npm run dev 和 python manage.py runserver 后,这是一切正常的状态,直到这里:

the status

最佳答案

更改此源代码:

document.getElementById('app')

...对此:

document.getElementById('App')

关于javascript - React.Js 未在 django 项目中渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59694929/

相关文章:

javascript - 在 AngularJS Controller 中获取带有 moment-timezone 的时区名称列表

javascript forEach 对数组/json 数据但按最新日期排序?

HTML 故障 : adsense ads randomly displaying with no ad code

javascript - 无法在 Safari 中使用 javascript 更改网站图标

mysql 服务器消失(错误#2006)

javascript - 构建 ES6 解析器和字符串生成器

javascript - 避免浏览器中涉及 Ajax 事件的弹出 block 的最佳实践

html - 用 CSS 打印 DIV

python - Django : LookupError: App ' doesn' t have a 'models' model

Django 'str' 对象在表单提交时不可调用