[英]How can I run Javascript on Django without exposing static files?
在我的 Django 网站上,我使用 Stripe 将付款集成到.js
文件中。
我注意到,当您在任何浏览器上“检查元素”时,此文件会出现在开发人员工具的 Sources 下。 任何人都可以访问此文件(可怕)。
如何重组我的文件组织,使apple-pay.js
不面向公众?
home.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
// Scripts for CSS and Stripe Pay
</head>
<body>
<section>
<div id="payment-request-button" data-amount="{{event.price}}" data-label=".
{{event.public_name}}">
<!-- A Stripe Element will be inserted here if the browser supports this type of payment method. -->
</div>
<div id="messages" role="alert"></div>
</section>
</body>
</html>
apple-pay.js
document.addEventListener('DOMContentLoaded', async () => {
const stripe = Stripe('pk_mykeyishere'); //need to protect this information and the other functions from bad actors
///functions I run here
});
我的文件结构:
├── Procfile
├── README.md
├── db.sqlite3
├── interface
│ ├── migrations
│ ├── models.py
│ ├── static
│ │ ├── apple-developer-merchantid-domain-association
│ │ └── interface
│ │ ├── apple-pay.js <------------------
│ │ ├── CSS/other JS files
│ ├── templates
│ │ └── interface
│ │ ├── home.html <-------------------
│ ├── urls.py
│ └── views.py
├── manage.py
└── AppName
├── settings.py
├── urls.py
└── wsgi.py
你不能对浏览器用户隐藏 JavaScript 代码,你只能缩小和/或模糊它,使人们更难阅读和理解。
Stripe 集成不需要您将敏感数据放入任何 JavaScript 文件中。 您应该在服务器端使用该数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.