Exploring Django: Where Did My Static File Go?

Currently working on a weather app project with Django, I seem to have misplaced my Javascript file in the static folder. This is resulting in a console error message: GET net::ERR_ABORTED 404 (Not Found)

I've structured my project files as shown below. Is this configuration accurate?

In addition to that, my settings.py includes the following:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

https://i.sstatic.net/Vrl1G.png

Answer №1

Create a fresh directory named project and transfer your project.js file to it.
Since Django typically operates with a assets folder within an application, when you access http://localhost:8000/assets/project/project.js in your situation, the correct link should be http://localhost:8000/assets/project.js

Answer №2

The default setting for your BASE_DIR is to point to the directory where your manage.py is located. Unless you've changed it, the file capstone.js can currently be found in the following path:

os.path.join(BASE_DIR, 'capstone/static')

However, Django typically searches for a static folder within each installed app, so in this case, using STATCFILES_DIRS may be unnecessary.

Ensure that you have included the static files in your urls.py.

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... add the rest of your URLconf here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

or

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    # ...include URLs here...
]

# static content urls
urlpatterns += staticfiles_urlpatterns()

This could be why you are encountering a 404 error.

Please note: if you already have set up static URLs, try accessing

 http://127.0.0.1:8000/static/capstone.js
instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to prevent an element from reaching the border of the screen?

As a JavaScript beginner, I am working on creating a simple game. My objective is to prevent the player (20px x 20px) box from causing the screen to scroll. I want a fixed screen where the player cannot go beyond the edges of the screen. Below are my previ ...

Display or Conceal Content Depending on the Button's Status

I am currently working on implementing an accordion style button for a project. I have configured my component to hide the list when the button is clicked, but I am encountering an issue where the list does not reappear. Additionally, I would like to inc ...

What steps are needed to troubleshoot and resolve issues with integrating Google reCaptcha in an AWS Lambda

I'm encountering an issue with my lambda function which is intended to validate google recaptcha. Despite sending the correct data (the response) from the client, I consistently receive a console message stating "verification failed". Below is the cod ...

Guide to setting up Mongodb with mongoose in the latest Next.js 13.3 update

I'm having trouble connecting MongoDB with Mongoose in Next.js 13.3 Version. I keep getting errors when trying to import the connectDb file or UserSchema file in api/getProducts/route.js file. Can someone please help me with step-by-step instructions ...

Unable to find a hidden JavaScript function

I'm facing an unusual challenge with my project. I'm currently developing a system using JSF2 (Java) and the Primefaces component library. I have multiple buttons triggering a JavaScript function called checkParams() on a onclick event. Now, I ne ...

"Fixing the issue of an undefined option being added to

In my controller, I have defined an object called tempScale: $scope.tempScale = { scaleType : [], deviations : [], intervals : 0 }; This object is connected to the HTML through this code: <select id="scales" ng-model="tempScale.scaleType" ...

Display validation in HTML5 only when the form is submitted

Here is the code snippet I am referring to: <input required pattern="[0-9]{5,10}" oninput="setCustomValidity('')" oninvalid="setCustomValidity('Type something')" /> I'm looking for a way to remove o ...

Launching numerous websites in separate browser tabs using the window.open function

I have a code snippet that opens one tab pointing to a website, but I need it to open two. For example: www.google.com and www.yahoo.com Currently, it only works with one site in the code: window.open("https://www.google.com"); but not when bot ...

What is the process for ordering by a many-to-many relationship in Sequelize?

I am dealing with a many-to-many relationship between User and Category, connected through the UserCategory model. Here is the code snippet illustrating this relationship: let user = await User.findAll({ where: { id: req.query.user }, attribut ...

Prevent my application from being idle (Cordova/Android)

I have recently developed an Android app using a node.js webpack project. After installing the app on my phone, I observed that it enters a sleep mode along with the phone. Consequently, a JavaScript timer I set up stops functioning as intended: pingTime ...

What is the correct way to accurately determine the width of a block being displayed with the flex-direction:column property?

For instance: HTML console.log($('.container').width()); // 600px as we defined in css. console.log($('.list').width()); // 600px console.log($('.box').eq('-1').position().left + $('.box').outerWidth( ...

What is the best way to utilize the $('input').on('change', function() method within AngularJS?

I am working on creating a registration form page using AngularJS and I need to display the percentage completed. The form consists of over 50 fields, so I am looking for a simple way to implement this functionality. Below is a snippet of the code I have ...

Jumping Face to Face with Transparency?

Working on a WebGL project utilizing the Three.js library, I've encountered an issue with rendering semi-transparent meshes. Depending on the camera angle, different objects appear to be on top when they should not. To demonstrate, I created a simple ...

What is the process for adding a personalized button tag within rows using material-table and TypeScript, and what specific properties does it anticipate receiving?

Hey, I have a few questions that I could use some help with :) I'm trying to add both an Avatar tag and an Edit Button to every row in my table, but the Edit Button appears on both. How can I move the action to the right side of the table? Also, how d ...

What is the best way to retrieve information from an external JSON file using Ionic?

I'm currently working on developing an app using the Ionic Framework. My goal is to retrieve data from an external JSON file by providing a token and parameter (1 for premium or 2 for basic). The URL displays the data correctly, but I am struggling ...

I'm looking to add multiple markers with multiple info windows using the Google Maps API. How can I achieve this?

Having trouble with the Google Maps API v3? I've set up a map with custom markers, but when clicked they all display the same content in the info window. Can you take a look at my code and help me troubleshoot? Each marker is supposed to link to a spe ...

How can a service be injected in NestJs based on its interface?

I have a module named payment.module.ts with the following setup: @Module({ controllers: [PaymentController], }) export class PaymentModule {} In my payment.service.ts file, I want to utilize a service that adheres to an interface. Here is an example ...

Popup will automatically close if the user does not respond

I have implemented a session timeout functionality that triggers a pop-up window after 30 minutes of inactivity, warning the user that their session is about to expire. Seeking assistance with: If the user locks their desktop and does not provide any inp ...

Dealing with an empty request.FILES using FileUploadParser in Django Rest Framework and Angular file upload technique

Uploading files in an angular view can sometimes be tricky, especially when using templates. The code snippet below shows how to upload multiple and single files using Angular File Upload library. Multiple <input type="file" name="file" nv-file-select= ...

Is there a way for a client server to automatically display updated data without requiring a request to be sent?

In my work designing an application for a restaurant, one standout feature is the ability for users to place orders online. These orders remain in a pending status until they are accepted or refused by the restaurant cashier or admin staff. I want to ensur ...