1

I am currently building out the front-end of a Django app and I want to use the official material design components.

However, I am running into trouble finding ways to integrate this; I want to be able to import the npm packages directly into javascript files and/or Django templates. Does anyone know how to do this?

2
  • I currently have a django-react project. I use material-ui. The approach I am using is that I created app in my django project called frontend and set up react using create-react-app in that app. So node's package.json is in that folder. Then I added a url configuration in django which matches everything and renders the index.html built by react. I take care of rest of the url routing in react. I had to go through all this because I don't want to allow cros headers. If you are ok with it, what that you can create a completely separate react project and host it somewhere else. Commented Jan 18, 2019 at 6:59
  • I you don't want to make your backend just an api. But render django templates with js. You will have to add js via cdn like this: <!-- Required MDC Web JavaScript library --> <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>, no npm/node required. But you shouldn't do this. It's right there on top(Quick Start) of material components readme, what's so complicated about it Commented Jan 18, 2019 at 7:02

1 Answer 1

1

if you using webpack, you need create correct config (webpack.config.js) a if you use npm run build need in

output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/static/youre-folder/dist/',
    filename: 'build.js'
  }

for example. And next include this adress '/static/youre-folder/dist/build.js' in template django.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.