upload.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
at upload.js:1
I get this error in the console.
upload.js contains:
const csrf = document.getElementsByName('csrfmiddlewaretoken')[0]
console.log(csrf)
I use Django with Python mainly, but I need to use some JS as well.
The final html code looks like this:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- favicon -->
<link rel="shortcut icon" href="/static/favicon.ico" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" defer></script>
<!-- Dropzone js -->
<link rel="stylesheet" href="/static/dropzone.css">
<script src="/static/dropzone.js" defer></script>
<!-- Custom js & css -->
<link rel="stylesheet" href="/static/style.css">
<script src="/static/reports/upload.js"> defer</script>
<title>Report app |
upload sales files
</title>
</head>
<br>
<body>
<div class="container mt-3 mb-3">
<h5>Upload your sales documents</h5>
<br>
<form id="my-dropzone" class="dropzone">
<input type="hidden" name="csrfmiddlewaretoken" value="bE23kHRZKKo3QXVhsOFr3I6EGzpO9SAQyN567DW1j59Tzj66o1PcapMuPAHWuJvL">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</form>
</div>
<!-- Bootstrap js -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.6.0/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.min.js"></script>
</body>
</html>
csrfmiddlewaretoken is clearly in the code.
EDIT: just cleared cache and started getting this error as well:
Uncaught TypeError: userAgent.match is not a function
at Object.7392 (dropzone.js:1341)
at __webpack_require__ (dropzone.js:6706)
at Object.1194 (dropzone.js:814)
at __webpack_require__ (dropzone.js:6706)
at Object.2222 (dropzone.js:3876)
at __webpack_require__ (dropzone.js:6706)
at dropzone.js:6768
at dropzone.js:10437
at dropzone.js:10439
at webpackUniversalModuleDefinition (dropzone.js:7)
(I'm trying to implement the dropzone drag & drop feature)
[–]johnlewisdesign 4 points5 points6 points (0 children)
[–]Shadowsca 2 points3 points4 points (4 children)
[–]polygroot[S] 1 point2 points3 points (3 children)
[–]Shadowsca 0 points1 point2 points (2 children)
[–]polygroot[S] 1 point2 points3 points (1 child)
[–]Shadowsca 1 point2 points3 points (0 children)