Django
ทำการตั้ง
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
ใน settings.py ของโปรเจคใหญ่
สร้าง folder static ใน app ของเราและเมื่อต้องการเรียกใช้ทำการแก้ template ดังเช่นตัวอย่าง
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'quiz/style.css' %}" />
Nodejs
ทำการลง และ import nodejs 'path' และ 'fs' (file system) ใน file index.js ของเรา
path ใช้ในการกำหนด path เส้นทาง file ตามชื่อ ส่วน file system ช่วยให้เราสามารถทำได้ดังนี้
- Read files
- Create files
- Update files
- Delete files
- Rename files
โดยเราใช้ในการ read file
( ข้อมูลเพื่มเติม path link , fs link)
ทดสอบ
แล้วใน template ของเรากำหนด src = "file path/Heading.png"
โดยที่ทดสอบผมใช้โฟลเดอร์ชื่อว่า public เก็บไฟล์รูป
ขั้นแรกตั้งค่า
path.join(__dirname, 'public')
แล้วจึงนำไปใส่ template
<img class="logo" src="public/Heading.png" alt="My_Logo">
ไม่มีความคิดเห็น:
แสดงความคิดเห็น