简体   繁体   中英

Django cannot find the djangular/app.js file via the urls.py config. How to troubleshoot?

I've spent a few days trying to figure this out and it's driving me up the wall. I'm limited on what I can copy and paste, so forgive the 'code brevity'. I also have a working version I developed and have uploaded it to GitHub .

I'm developing a Django website that also uses AngularJS, so I'm using the djangular package, specifically the bit that lets me import Django variables into Angular. This is the section from GitHub:

To use the AngularJS module that Djangular provides you, you'll need to add the djangular app to your projects URLs.

  urlpatterns = patterns('', ... url(r'^djangular/', include('djangular.urls')), ... ) 

And I've placed this in my project/urls.py file. I've done the same with my GitHub repository.

When I reference that URL in my appName/app/index.html , I do so like this:

<script src="{% static 'djangular/app.js' %}"></script>

But that leads to a 500 response from the server as Angular produces the Module 'djangular' is not available! error. What should be happening is that the URL djangular/app.js in the script tag above, should redirect to urls.py inside the Djangular folder in the Python site-packages , which then points to DjangularModuleTemplateView.as_view() . This seems to work in my GitHub version, but not in the local version I have for some reason.

If I have my script tag without the "{%static '...'%}" part I still get a 500, with the same error:

<script src="/djangular/app.js"></script>

What config could I possibly have overlooked that's causing the app not to find the right Djangular config? I've stared at both configurations so long my eyes are glazing over, and I'm struggling to find any differences. What else could it be?

I'm more than happy to provide more details if needed to answer this question.

I managed to solve this myself by running ./manage syncdb

This creates various tables (the user table, and the session table at least) which are required for Djangular to run.

Then I double checked all my <script> imports/includes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM