0

I have an odd case where I'm trying to serve a static index.html file that holds a javascript bundle from webpack in it for vue.js files, but it is sending the incorrect javascript file contents.

I've tried both sending the html file as a template view and simply reading the file contents and sending it as an html response. It sends the html file itself correctly, but instead of sending the contents of the javascript file it just copies the index.html content into the javascript file.

I checked to make sure that I wasn't accidentally overwriting the javascript file with html content and that's not the case, the javascript is in correct form, but when it is sent to the browser this is what is seen:

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>testprojsimple</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="js/myvuejs.bundle.js"></script>
  </body>`
</html>

myvuejs.bundle.js:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>testprojsimple</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="js/myvuejs.bundle.js"></script>
  </body>`
</html>

Any ideas on why it would be re-sending the index.html content as the javascript file as well?

Edit:

I'm in development mode currently, serving by simply saying in views:

def indexView(request):
    return HttpResponse(open("file/to/static/html/file/index.html").read())

Settings.py:

STATIC_ROOT = os.path.join(BASE_DIR,'static/')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

urls.py:

urlpatterns = [
    url(r'^', indexView),
]

My goal is to avoid serverside rendering, using client-side frameworks to reach into a django backend that serves data content, like json, etc...

4
  • You haven't posted nearly enough information. How are you serving static files? How are you serving your index page? Are you running with the development server, or in production with a different server? How is that configured? Commented May 20, 2018 at 18:58
  • @DanielRoseman sorry, edited Commented May 20, 2018 at 19:05
  • You need to show the rest of that view and the URLs. Commented May 20, 2018 at 19:14
  • edited again, added urls.py and the rest of the views. i'm trying to keep it as simple as possible to start to get it working before I add more which is why they look so small @DanielRoseman Commented May 20, 2018 at 19:17

1 Answer 1

1

The regex ^ matches every single URL; it just means "any string that starts", which of course is every string. You should terminate the pattern as well: ^$, so that it only captures the empty string.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that fixed part of it, now it's just complaining it can't find the file so i need to figure out how to retrieve the static js file without using templating

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.