When i had the JS directly in the HTML file, everything worked as expected. Since I moved it to a spots.js file, it doesn't load or appear in the network tab, but i can reach it by going to file location in the server. I am in Debug mode.
In my settings.py I have:
STATIC_URL = '/users/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'var', 'static')
In my urls.py, I have:
urlpatterns = [
path('', home, name='users-home'),
path('register/', RegisterView.as_view(), name='users-register'),
path('profile/', profile, name='users-profile'),
path('select-spots/', select_spots, name='select-spots'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
In my views.py I have:
@login_required
def select_spots(request):
spots = []
with open('spotscsv.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
spots.append({
'name': row['name'],
'latitude': float(row['latitude']),
'longitude': float(row['longitude']),
})
return render(request, 'users/select_spots.html', {'spots': spots})
And in my select_spots.html, I have:
{% extends 'users/base.html' %}
{% load static %}
<script src="{% static 'myapp/spots.js' %}"></script>
Folder structure:
I tried changing the spots location, modifying code, running collectstatic
with no luck.