0

我在向下滚动时使用 Twitter 样式分页来加载我的提要。一切正常。

问题在于同一模板上有多个分页。我已经按照此处的说明编写了代码。

但我收到了这个奇怪的错误:

Error during template rendering at line in other_entries_page.html::

{% paginate activity_obj using activity %}

错误显示为:

VariableDoesNotExist 在 /accounts/home/

Failed lookup for key [activity] in u'[{\'False\': False, \'None\': None, \'True\': True}, {u\'csrf_token\': <django.utils.functional.__proxy__ object at 0x7fa56404b5d0>}, {\'perms\': <django.contrib.auth.context_processors.PermWrapper object at 0x7fa56404bf10>, \'user\': <django.utils.functional.SimpleLazyObject object at 0x7fa564034710>}, {}, {u\'LANGUAGES\': ((\'af\', \'Afrikaans\'), (\'ar\', \'Arabic\'), (\'az\', \'Azerbaijani\'), (\'bg\', \'Bulgarian\'), (\'be\', \'Belarusian\'), (\'bn\', \'Bengali\'), (\'br\', \'Breton\'), (\'bs\', \'Bosnian\'), (\'ca\', \'Catalan\'), (\'cs\', \'Czech\'), (\'cy\', \'Welsh\'), (\'da\', \'Danish\'), (\'de\', \'German\'), (\'el\', \'Greek\'), (\'en\', \'English\'), (\'en-gb\', \'British English\'), (\'eo\', \'Esperanto\'), (\'es\', \'Spanish\'), (\'es-ar\', \'Argentinian Spanish\'), (\'es-mx\', \'Mexican Spanish\'), (\'es-ni\', \'Nicaraguan Spanish\'), (\'es-ve\', \'Venezuelan Spanish\'), (\'et\', \'Estonian\'), (\'eu\', \'Basque\'), (\'fa\', \'Persian\'), (\'fi\', \'Finnish\'), (\'fr\', \'French\'), (\'fy-nl\', \'Frisian\'), (\'ga\', \'Irish\'), (\'gl\', \'Galician\'), (\'he\', \'Hebrew\'), (\'hi\', \'Hindi\'), (\'hr\', \'Croatian\'), (\'hu\', \'Hungarian\'), (\'ia\', \'Interlingua\'), (\'id\', \'Indonesian\'), (\'is\', \'Icelandic\'), (\'it\', \'Italian\'), (\'ja\', \'Japanese\'), (\'ka\', \'Georgian\'), (\'kk\', \'Kazakh\'), (\'km\', \'Khmer\'), (\'kn\', \'Kannada\'), (\'ko\', \'Korean\'), (\'lb\', \'Luxembourgish\'), (\'lt\', \'Lithuanian\'), (\'lv\', \'Latvian\'), (\'mk\', \'Macedonian\'), (\'ml\', \'Malayalam\'), (\'mn\', \'Mongolian\'), (\'nb\', \'Norwegian Bokmal\'), (\'ne\', \'Nepali\'), (\'nl\', \'Dutch\'), (\'nn\', \'Norwegian Nynorsk\'), (\'pa\', \'Punjabi\'), (\'pl\', \'Polish\'), (\'pt\', \'Portuguese\'), (\'pt-br\', \'Brazilian Portuguese\'), (\'ro\', \'Romanian\'), (\'ru\', \'Russian\'), (\'sk\', \'Slovak\'), (\'sl\', \'Slovenian\'), (\'sq\', \'Albanian\'), (\'sr\', \'Serbian\'), (\'sr-latn\', \'Serbian Latin\'), (\'sv\', \'Swedish\'), (\'sw\', \'Swahili\'), (\'ta\', \'Tamil\'), (\'te\', \'Telugu\'), (\'th\', \'Thai\'), (\'tr\', \'Turkish\'), (\'tt\', \'Tatar\'), (\'udm\', \'Udmurt\'), (\'uk\', \'Ukrainian\'), (\'ur\', \'Urdu\'), (\'vi\', \'Vietnamese\'), (\'zh-cn\', \'Simplified Chinese\'), (\'zh-tw\', \'Traditional Chinese\')), u\'LANGUAGE_BIDI\': False, u\'LANGUAGE_CODE\': \'en-us\'}, {u\'MEDIA_URL\': \'/media/\'}, {u\'STATIC_URL\': \'/static/\'}, {u\'TIME_ZONE\': \'Asia/Kolkata\'}, {u\'request\': <WSGIRequest\npath:/accounts/home/,\nGET:<QueryDict: {}>,\nPOST:<QueryDict: {}>,\nCOOKIES:{\'csrftoken\': \'EqzLQqDxLReLeY9748OIFavZYGIyEKu6\',\n \'sessionid\': \'7ghle3l0naigipqq5kvwbr6tbmw65ul7\'},\nMETA:{\'COLORTERM\': \'gnome-terminal\',\n \'COMPIZ_CONFIG_PROFILE\': \'ubuntu\',\n \'CONTENT_LENGTH\': \'\',\n \'CONTENT_TYPE\': \'text/plain\',\n u\'CSRF_COOKIE\': u\'EqzLQqDxLReLeY9748OIFavZYGIyEKu6\',\n u\'CSRF_COOKIE_USED\': True,\n \'DBUS_SESSION_BUS_ADDRESS\': \'unix:abstract=/tmp/dbus-VdpkiAyrl4,guid=2d795369fb38e64bfe3402be00000019\',\n \'DEFAULTS_PATH\': \'/usr/share/gconf/ubuntu.default.path\',\n \'DESKTOP_SESSION\': \'ubuntu\',\n \'DISPLAY\': \':0\',\n \'DJANGO_SETTINGS_MODULE\': \'doroko.settings\',\n \'GATEWAY_INTERFACE\': \'CGI/1.1\',\n \'GDMSESSION\': \'ubuntu\',\n \'GNOME_DESKTOP_SESSION_ID\': \'this-is-deprecated\',\n \'GNOME_KEYRING_CONTROL\': \'/tmp/keyring-FV73UN\',\n \'GPG_AGENT_INFO\': \'/tmp/keyring-FV73UN/gpg:0:1\',\n \'HOME\': \'/home/deep\',\n \'HTTP_ACCEPT\': \'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\',\n \'HTTP_ACCEPT_ENCODING\': \'gzip, deflate\',\n \'HTTP_ACCEPT_LANGUAGE\': \'en-US,en;q=0.5\',\n \'HTTP_CACHE_CONTROL\': \'max-age=0\',\n \'HTTP_CONNECTION\': \'keep-alive\',\n \'HTTP_COOKIE\': \'csrftoken=EqzLQqDxLReLeY9748OIFavZYGIyEKu6; sessionid=7ghle3l0naigipqq5kvwbr6tbmw65ul7\',\n \'HTTP_HOST\': \'127.0.0.1:8000\',\n \'HTTP_USER_AGENT\': \'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0\',\n \'LANG\': \'en_IN\',\n \'LANGUAGE\': \'en_IN:en\',\n \'LOGNAME\': \'deep\',\n \'MANDATORY_PATH\': \'/usr/share/gconf/ubuntu.mandatory.path\',\n \'OLDPWD\': \'/home/deep\',\n \'PATH\': \'/home/deep/.virtualenvs/django_project/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games\',\n \'PATH_INFO\': u\'/accounts/home/\',\n \'PROJECT_HOME\': \'/home/deep/dev\',\n \'PS1\': \'(django_project)${debian_chroot:+($debian_chroot)}\\\\u@\\\\h:\\\\w\\\\$ \',\n \'PWD\': \'/home/deep/doroko\',\n \'QUERY_STRING\': \'\',\n \'REMOTE_ADDR\': \'127.0.0.1\',\n \'REMOTE_HOST\': \'\',\n \'REQUEST_METHOD\': \'GET\',\n \'RUN_MAIN\': \'true\',\n \'SCRIPT_NAME\': u\'\',\n \'SERVER_NAME\': \'localhost\',\n \'SERVER_PORT\': \'8000\',\n \'SERVER_PROTOCOL\': \'HTTP/1.1\',\n \'SERVER_SOFTWARE\': \'WSGIServer/0.1 Python/2.7.3\',\n \'SESSION_MANAGER\': \'local/deep-ThinkPad-Edge:@/tmp/.ICE-unix/1440,unix/deep-ThinkPad-Edge:/tmp/.ICE-unix/1440\',\n \'SHELL\': \'/bin/bash\',\n \'SHLVL\': \'1\',\n \'SSH_AGENT_PID\': \'1612\',\n \'SSH_AUTH_SOCK\': \'/tmp/keyring-FV73UN/ssh\',\n \'TERM\': \'xterm\',\n \'TZ\': \'Asia/Kolkata\',\n \'UBUNTU_MENUPROXY\': \'libappmenu.so\',\n \'USER\': \'deep\',\n \'VIRTUALENVWRAPPER_HOOK_DIR\': \'/home/deep/.virtualenvs\',\n \'VIRTUALENVWRAPPER_PROJECT_FILENAME\': \'.project\',\n \'VIRTUAL_ENV\': \'/home/deep/.virtualenvs/django_project\',\n \'WINDOWID\': \'54525958\',\n \'WORKON_HOME\': \'/home/deep/.virtualenvs\',\n \'XAUTHORITY\': \'/home/deep/.Xauthority\',\n \'XDG_CONFIG_DIRS\': \'/etc/xdg/xdg-ubuntu:/etc/xdg\',\n \'XDG_CURRENT_DESKTOP\': \'Unity\',\n \'XDG_DATA_DIRS\': \'/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/\',\n \'XDG_SEAT_PATH\': \'/org/freedesktop/DisplayManager/Seat0\',\n \'XDG_SESSION_COOKIE\': \'ad07b878f48a1b9b3d36cc7b0000000b-1379145947.877521-2075140020\',\n \'XDG_SESSION_PATH\': \'/org/freedesktop/DisplayManager/Session0\',\n \'_\': \'./manage.py\',\n \'wsgi.errors\': <open file \'<stderr>\', mode \'w\' at 0x7fa57dfdd270>,\n \'wsgi.file_wrapper\': <class wsgiref.util.FileWrapper at 0x2bd96d0>,\n \'wsgi.input\': <socket._fileobject object at 0x7fa56c2a7950>,\n \'wsgi.multiprocess\': False,\n \'wsgi.multithread\': True,\n \'wsgi.run_once\': False,\n \'wsgi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>}, {\'feed_obj\': [<Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, <Feed: Feed object>, \'...(remaining elements truncated)...\'], \'activity_obj\': [<Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Talk_comment: Talk_comment object>, <Friendship: Friendship object>, <Friendship: Friendship object>, <Friendship: Friendship object>, <Friendship: Friendship object>, <Friendship: Friendship object>], u\'page_template\': \'feed.html\'}, {\'block\': <Block Node: content. Contents: [<Text Node: \'\n\n <div class="wrapper">\n\'>, <Variable Node: talk_form.as_p>, <Text Node: \'\n\t\t\t<input type="submit" \'>, <django.template.defaulttags.CsrfTokenNode object at 0x7fa56c4f5d90>, <Text Node: \'\n\t\t</form>\n\t\t\n\t\t\n\t </div>\'>, <django.template.loader_tags.ConstantIncludeNode object at 0x7fa5600ab190>, <Text Node: \'\n\t\t\t</div>\n\t\t\t\n\t</div>\n\n\n\'>, <django.template.loader_tags.ConstantIncludeNode object at 0x7fa5600ab390>, <Text Node: \'\n\t</div>\n\t\n\t</div>\n</div>\'>, <Block Node: js. Contents: [<Text Node: \'\n\t\'>, <Variable Node: block.super>, <Text Node: \'\n\t<script src="http://cod\'>, <Variable Node: STATIC_URL>, <Text Node: \'js/endless.js"></script>\n\'>, <Variable Node: STATIC_URL>, <Text Node: \'js/endless_on_scroll.js">\'>, <Variable Node: STATIC_URL>, <Text Node: \'js/endless-pagination.js"\'>]>, <Text Node: \'\n\'>]>}]'

无法理解此错误消息的含义。请帮忙。

4

1 回答 1

2

该错误表明该变量activity在上下文中不存在。您要么需要将其添加到视图中的上下文中,要么根本不需要变量。你可以像这样传递一个字符串:{% paginate activity_obj using "activity" %}. 所以这取决于你想要做什么。如果您的查询字符串参数名称实际上是 string "activity",那么只需activity用引号括起来。如果您在视图代码中动态设置变量,那么您需要将它放在上下文中,以便您可以在模板中访问它。

于 2013-09-16T23:41:01.240 回答