I am trying to serve a static svg file on my local Django server. The file is quite large so I don't want to put it directly into my HTML. It shows
This XML file does not appear to have any style information associated with it. The document tree is shown below. And then my svg.
I have tried adding the following code in case Django couldn't identify svgs:
import mimetypes
mimetypes.add_type("image/svg+xml", ".svg", True)
mimetypes.add_type("image/svg+xml", ".svgz", True)
but it didn't help. It just served with the correct mime type. I believe the problem is in the Content-Disposition header, because compare the two responses:
curl -i https://www.google.com/chrome/static/images/chrome-logo-m100.svg:
HTTP/2 200
accept-ranges: bytes
vary: Accept-Encoding, Sec-Ch-Ua-Full-Version-List, Sec-Ch-Ua-Platform, Sec-Ch-Ua-Platform-Version, Sec-CH-Prefers-Reduced-Motion
content-type: image/svg+xml
content-security-policy-report-only: require-trusted-types-for 'script'; report-uri https://csp.withgoogle.com/csp/uxe-owners-acl/chrome
cross-origin-resource-policy: cross-origin
cross-origin-opener-policy-report-only: same-origin; report-to="uxe-owners-acl/chrome"
report-to: {"group":"uxe-owners-acl/chrome","max_age":2592000,"endpoints":[{"url":"https://csp.withgoogle.com/csp/report-to/uxe-owners-acl/chrome"}]}
content-length: 2303
date: Sun, 26 Nov 2023 20:19:47 GMT
expires: Sun, 26 Nov 2023 20:19:47 GMT
cache-control: private, max-age=31536000
last-modified: Wed, 02 Mar 2022 19:00:00 GMT
x-content-type-options: nosniff
accept-ch: Sec-Ch-Ua-Full-Version-List, Sec-Ch-Ua-Platform, Sec-Ch-Ua-Platform-Version, Sec-CH-Prefers-Reduced-Motion
critical-ch: Sec-Ch-Ua-Full-Version-List, Sec-Ch-Ua-Platform, Sec-Ch-Ua-Platform-Version, Sec-CH-Prefers-Reduced-Motion
server: sffe
x-xss-protection: 0
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
<svg fill="none" height="63" viewBox="0 0 63 63" width="63" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="34.9087" x2="7.63224" y1="61.029" y2="13.7847"><stop offset="0" stop-color="#1e8e3e"/><stop offset="1" stop-color="#34a853"/></linearGradient><linearGradient id="b" gradientUnits="userSpaceOnUse" x1="26.9043" x2="54.1808" y1="63.0788" y2="15.8345"><stop offset="0" stop-color="#fcc934"/><stop offset="1" stop-color="#fbbc04"/></linearGradient><linearGradient id="c" gradientUnits="userSpaceOnUse" x1="4.22145" x2="58.7745" y1="19.6884" y2="19.6884"><stop offset="0" stop-color="#d93025"/><stop offset="1" stop-color="#ea4335"/></linearGradient><path d="m31.499 47.2466c8.6985 0 15.75-7.0515 15.75-15.75s-7.0515-15.75-15.75-15.75-15.75 7.0515-15.75 15.75 7.0515 15.75 15.75 15.75z" fill="#fff"/><path d="m17.8591 39.3751-13.63772-23.6212c-2.76527 4.788-4.22118922 10.2197-4.22137998 15.7489s1.45535998 10.961 4.22028998 15.7492c2.76494 4.7882 6.74181 8.7641 11.53071 11.5279 4.7889 2.7637 10.221 4.2179 15.7502 4.2164l13.6377-23.6212v-.0041c-1.3813 2.3954-3.369 4.3848-5.7632 5.7681s-5.1104 2.1118-7.8755 2.1122-5.4816-.7272-7.8762-2.1099c-2.3945-1.3826-4.3829-3.3714-5.7649-5.7663z" fill="url(#a)"/><path d="m45.1379 39.3741-13.6376 23.6212c5.5292.0008 10.9611-1.4542 15.7496-4.2187 4.7885-2.7644 8.7648-6.7408 11.5291-11.5294 2.7642-4.7887 4.219-10.2207 4.2181-15.7499-.001-5.5292-1.4577-10.9606-4.2237-15.7483h-27.2754l-.0034.0021c2.7651-.0014 5.4818.7254 7.8769 2.1071 2.3951 1.3818 4.3841 3.3698 5.767 5.7643 1.3829 2.3944 2.1109 5.1108 2.1109 7.8758-.0001 2.7651-.7283 5.4814-2.1113 7.8758z" fill="url(#b)"/><path d="m31.499 43.9688c6.8863 0 12.4688-5.5825 12.4688-12.4688s-5.5825-12.4688-12.4688-12.4688-12.4687 5.5825-12.4687 12.4688 5.5824 12.4688 12.4687 12.4688z" fill="#1a73e8"/><path d="m31.4991 15.75h27.2754c-2.764-4.7888-6.74-8.76553-11.5283-11.53029-4.7883-2.76475-10.2202-4.22010235-15.7494-4.21970992s-10.9608 1.45650992-15.7487 4.22194992c-4.788 2.76543-8.76341 6.74275-11.52666 11.53185l13.63766 23.6212.0035.0019c-1.3837-2.394-2.1127-5.11-2.1136-7.8751s.7264-5.4817 2.1086-7.8765c1.3821-2.3948 3.3706-4.3835 5.7652-5.7659 2.3947-1.3825 5.1112-2.11 7.8763-2.1094z" fill="url(#c)"/></svg>
curl -i https://localhost:8000/static/goodreads.svg:
HTTP/1.1 200 OK
Date: Sun, 26 Nov 2023 20:21:16 GMT
Server: WSGIServer/0.2 CPython/3.11.6
Content-Type: image/svg+xml
Content-Length: 7336
Content-Disposition: inline; filename="goodreads.svg"
Last-Modified: Sun, 26 Nov 2023 16:37:21 GMT
<svg width="430" height="150" viewBox="0 0 4450 1500">
<defs>
<linearGradient id="bg" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stop-color="#f7f3ea"/>
<stop offset="100%" stop-color="#eee3cf"/>
</linearGradient>
</defs>
<rect x="0" y="0" width="4450" height="1500" fill="url(#bg)" rx="100" ry="100"/>
<g transform="scale(0.6, -0.6) translate(0,-900)">
<path d="M80 0L80 716L296 716Q408 716 489 670.50Q570 625 614 544Q658 463 658 358Q658 253 614 172.50Q570 92 489 46Q408 0 296 0L80 0M165 81L296 81Q380 81 442 113.50Q504 146 538 208Q572 270 572 358Q572 446 538 508Q504 570 442 602.50Q380 635 296 635L165 635L165 81Z"/>
<path d="M71 0L71 510L156 510L156 0L71 0M113 604Q88 604 70 622Q52 640 52 665Q52 691 70 708.50Q88 726 113 726Q139 726 156.50 708.50Q174 691 174 665Q174 640 156.50 622Q139 604 113 604Z" transform="translate(700,0)"/>
<path d="M241-16Q184-16 140.50 2.50Q97 21 68.50 52.50Q40 84 26 121L102 155Q122 109 160 84Q198 59 247 59Q294 59 325.50 78Q357 97 357 134Q357 157 344 172.50Q331 188 306 199Q281 210 245 219L183 235Q147 245 115 263Q83 281 63.50 309.50Q44 338 44 379Q44 425 71 458Q98 491 142 508.50Q186 526 236 526Q280 526 318.50 513.50Q357 501 386 476.50Q415 452 430 416L356 382Q337 420 305 435Q273 450 234 450Q192 450 161 431.50Q130 413 130 381Q130 349 155.50 333Q181 317 218 307L292 288Q367 269 405 231.50Q443 194 443 140Q443 92 416 57Q389 22 343 3Q297-16 241-16Z" transform="translate(930,0)"/>
<path d="M294-16Q219-16 160.50 19.50Q102 55 69 116.50Q36 178 36 255Q36 333 69 394Q102 455 160.50 490.50Q219 526 294 526Q380 526 435.50 486.50Q491 447 514 385L437 353Q418 400 380.50 424.50Q343 449 290 449Q245 449 206.50 425Q168 401 144 357.50Q120 314 120 255Q120 197 144 153Q168 109 206.50 85Q245 61 290 61Q344 61 383 86Q422 111 441 157L517 125Q492 66 436 25Q380-16 294-16Z" transform="translate(1400,0)"/>
<path d="M298-16Q221-16 162 20Q103 56 69.50 117.50Q36 179 36 255Q36 331 69.50 392.50Q103 454 162 490Q221 526 298 526Q375 526 434 489.50Q493 453 526.50 391.50Q560 330 560 255Q560 179 526.50 117.50Q493 56 434 20Q375-16 298-16M298 61Q344 61 384.50 84Q425 107 450 150.50Q475 194 475 255Q475 316 450 359.50Q425 403 384.50 426Q344 449 298 449Q252 449 211 426Q170 403 145 359.50Q120 316 120 255Q120 194 145 150.50Q170 107 211 84Q252 61 298 61Z" transform="translate(1930,0)"/>
<path d="M213 0L7 510L98 510L256 100L258 100L418 510L507 510L299 0L213 0Z" transform="translate(2500,0)"/>
<path d="M290-16Q216-16 158.50 19Q101 54 68.50 115Q36 176 36 254Q36 327 66.50 389Q97 451 152.50 488.50Q208 526 283 526Q359 526 413.50 492.50Q468 459 497.50 400Q527 341 527 265Q527 258 526.50 251Q526 244 525 239L86 239L86 309L437 309Q436 330 427.50 354.50Q419 379 400.50 400.50Q382 422 353.50 435.50Q325 449 283 449Q233 449 196.50 423.50Q160 398 140.50 354Q121 310 121 254Q121 189 146 146Q171 103 210.50 82Q250 61 293 61Q349 61 385.50 87.50Q422 114 444 153L516 118Q486 60 430 22Q374-16 290-16Z" transform="translate(3000,0)"/>
<path d="M63 0L63 510L144 510L144 428L148 428Q158 457 181.50 478.50Q205 500 235.50 512.50Q266 525 296 525Q319 525 332 522.50Q345 520 356 515L356 423Q340 431 321.50 435Q303 439 284 439Q247 439 216 418Q185 397 166.50 362Q148 327 148 285L148 0L63 0Z" transform="translate(3540,0)"/>
<path d="M71 0L71 510L156 510L156 0L71 0M113 604Q88 604 70 622Q52 640 52 665Q52 691 70 708.50Q88 726 113 726Q139 726 156.50 708.50Q174 691 174 665Q174 640 156.50 622Q139 604 113 604Z" transform="translate(4100,0)"/>
<path d="M28 510L327 510L327 433L28 433L28 510M117 134L117 654L202 654L202 155Q202 115 218.50 93Q235 71 273 71Q290 71 304 76Q318 81 329 88L329 5Q316-1 300.50-4.50Q285-8 259-8Q195-8 156 29.50Q117 67 117 134Z" transform="translate(4300,0)"/>
<path d="M298-16Q221-16 162 20Q103 56 69.50 117.50Q36 179 36 255Q36 331 69.50 392.50Q103 454 162 490Q221 526 298 526Q375 526 434 489.50Q493 453 526.50 391.50Q560 330 560 255Q560 179 526.50 117.50Q493 56 434 20Q375-16 298-16M298 61Q344 61 384.50 84Q425 107 450 150.50Q475 194 475 255Q475 316 450 359.50Q425 403 384.50 426Q344 449 298 449Q252 449 211 426Q170 403 145 359.50Q120 316 120 255Q120 194 145 150.50Q170 107 211 84Q252 61 298 61Z" transform="translate(4860, 0)"/>
<path d="M63 0L63 510L144 510L144 435L148 435Q168 472 213.50 499Q259 526 313 526Q407 526 454.50 471.50Q502 417 502 327L502 0L417 0L417 314Q417 388 381.50 418.50Q346 449 290 449Q248 449 216 425.50Q184 402 166 365Q148 328 148 287L148 0L63 0Z" transform="translate(5400, 0)"/>
</g>
<g transform="scale(1,-1) translate(0, -650)">
<path d="M454 32q0-83-26-126-46-82-174-82Q78-176 70-27h19q5-49 24-76 40-56 140-56 108 0 150 61 32 45 32 141v120q-12-34-28-57-56-80-161-80-94 0-147 62-54 61-54 169 0 105 56 170 57 64 149 64 141 0 185-141v128h19V32M250 474q-84 0-135-59-51-60-51-159 0-97 49-155t131-58q87 0 139 58 52 59 52 156 0 98-51 157-51 60-134 60Z" transform=" translate(0,-650)"/>
<path d="M267 491q95 0 152-70 58-71 58-186 0-112-59-180-58-68-156-68-99 0-158 69-59 68-59 183 0 114 61 183t161 69m-2-17q-90 0-145-64-56-64-56-167 0-110 53-175Q171 4 262 4q89 0 143 63 53 63 53 168 0 107-53 173t-140 66Z" transform=" translate(500,-650)"/>
<path d="M267 491q95 0 152-70 58-71 58-186 0-112-59-180-58-68-156-68-99 0-158 69-59 68-59 183 0 114 61 183t161 69m-2-17q-90 0-145-64-56-64-56-167 0-110 53-175Q171 4 262 4q89 0 143 63 53 63 53 168 0 107-53 173t-140 66Z" transform="translate(1000,-650)"/>
<path d="M465 0h-19v137Q406-13 253-13q-96 0-152 66T45 233q0 119 57 189 58 69 156 69 94 0 151-72 19-23 37-71v319h19V0M254 474q-88 0-139-64-51-65-51-175Q64 4 252 4q89 0 141 64 52 63 52 171t-52 172q-51 63-139 63Z" transform="translate(1500,-650)"/>
<path d="M325 414h-4l-2 1-19 1q-63 0-105-42-46-47-46-186V0H70v483h74V382q50 115 181 115v-83Z" transform="translate(2000,-650)"/>
<path d="M480 155Q443-14 268-14q-105 0-166 68-62 68-62 185 0 113 64 186 63 72 162 72 146 0 199-132 21-56 20-143H122q4-169 152-169 95 0 128 102h78m-77 132q-11 144-139 144-123 0-141-144h280Z" transform="translate(2300,-650)"/>
<path d="M485 2Q458-8 429-8q-69 0-69 72-68-78-175-78Q30-14 30 123q0 98 95 134 33 12 76 17l69 9q85 9 85 64 0 84-109 84t-119-99H49q5 165 205 165 99 0 149-47 33-32 33-119v-51l-4-174q0-47 32-47 10 0 21 5V2M356 251q-25-19-107-29-70-9-96-23-41-20-41-69 0-82 94-82 89 0 135 65 15 21 15 66v72Z" transform="translate(2800,-650)"/>
<path d="M496 0h-75v71q-38-85-156-85-104 0-164 69-61 68-61 185 0 121 60 188 61 69 160 69 112 0 157-81v251h79V0M268 430q-147 0-147-190 0-83 41-135t108-52q149 0 149 189 0 96-45 144-41 44-106 44Z" transform="translate(3300,-650)"/>
<path d="M331 343q-13 87-116 87-101 0-101-66 0-37 38-52 16-8 91-25 100-22 142-52 45-34 45-94 0-71-55-113T226-14Q28-14 22 153h78Q112 53 230 53t118 81q0 39-48 59-23 10-73 21l-47 12q-22 5-32 8Q33 263 33 355q0 142 184 142 109 0 159-59 30-33 34-95h-79Z" transform="translate(3800,-650)"/>
<path d="M425 525q51 0 81-17 51-29 51-87 0-66-57-93 26-11 37-33 7-14 11-42l4-41q4-47 14-57l13-13h-74q-12 16-13 49-4 75-19 94-16 19-72 19H300V142h-62v383h187M300 353h95q100 0 100 61 0 59-86 59H300V353m93 329q143 0 245-102t102-246q0-145-102-247T393-15Q248-15 146 87T44 334q0 144 102 246t247 102m0-49q-123 0-209-88-87-87-87-211 0-125 87-212 86-88 209-88 122 0 208 88t86 212q0 124-86 211-86 88-208 88Z" transform="translate(4200, -200) scale(0.3)"/>
</g>
</svg>
The main difference is the Content-Disposition header. Is there any way to server specific files (*.svg,*.svgz) without the header?