Error importing external library into Django template tag library

So, I'm trying to write a Django reuse application that provides a way to display your Twitter feed on your page. I know well that it already exists 20 times. This is an academic exercise. :)

The directory structure is quite simple:

myproject
|__  __init__.py
|__  manage.py
|__  settings.py
|__  myapp
     |__  __init__.py
     |__  admin.py
     |__  conf
          |__  __init__.py
          |__  appsettings.py
     |__  feedparser.py
     |__  models.py
     |__  templates
          |__  __init__.py
     |__  templatetags
          |__  __init__.py
          |__  twitterfeed.py
     |__  views.py
|__  templates
          |__  base.html
|__  urls.py

When starting the Django shell, the functions defined in twitterfeed.py work fine. I also believe that I have template tags correctly named and registered.

As you can see, I use the excellent Universal Parser . My problem is not in UFP itself, but in UFP of the inability to invoke the template tag library when importing. When I'm {% load twitterfeed %}in base.py, I get the following error:

'twitterfeed' : django.templatetags.twitterfeed, No feedparser

feedparser, :

import re, datetime, time, myapp.feedparser

, , . , , , ImportError, Django.

- feedparser.py , - - PythonPath?

!

+3
2

, Python 2.6 ( ..feedparser ..), . , feedparser.py templatetags, twitterfeed.py

+2

( , ) . -, "ext" ( myproject/ext). , feedparser ext - myproject/ext/feedparser

, manage.py script, ext/ sys.path. , ./manage.py runserver, ./manage.py shell :

# manage.py
import os, sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'ext'))
# ... rest of manage.py

, , , virtualenvs. , , , - , sys.path.insert mod_wsgi app.wsgi.

+5

Source: https://habr.com/ru/post/1713584/


All Articles