[英]Django-postman not working
我試圖為用戶到用戶的消息傳遞系統實現Django-postman
。
我克隆了 repo 並在我的settings.py
和URLs.py
文件中也這樣做了:
在主文件的URLs.py
,我包含了:
re_path(r'^messages/', include('postman.urls', namespace='postman')),
在 Settings.py 文件中,我包含了:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'postman',
'account',
'landingpage',
]
POSTMAN_I18N_URLS = True # default is False
POSTMAN_DISALLOW_ANONYMOUS = True # default is False
POSTMAN_DISALLOW_MULTIRECIPIENTS = True # default is False
POSTMAN_DISALLOW_COPIES_ON_REPLY = True # default is False
POSTMAN_DISABLE_USER_EMAILING = True # default is False
POSTMAN_FROM_EMAIL = 'from@host.tld' # default is DEFAULT_FROM_EMAIL
#POSTMAN_PARAMS_EMAIL = get_params_email # default is None
POSTMAN_AUTO_MODERATE_AS = True # default is None
POSTMAN_SHOW_USER_AS = 'get_full_name' # default is None
POSTMAN_NAME_USER_AS = 'last_name' # default is None
POSTMAN_QUICKREPLY_QUOTE_BODY = True # default is False
POSTMAN_NOTIFIER_APP = None # default is 'notification'
POSTMAN_MAILER_APP = None # default is 'mailer'
郵遞員網址:
urlpatterns = [
# Translators: keep consistency of the <option> parameter with the translation for 'm'
url(pgettext_lazy('postman_url', r'^inbox/(?:(?P<option>m)/)?$'), InboxView.as_view(), name='inbox'),
# Translators: keep consistency of the <option> parameter with the translation for 'm'
url(pgettext_lazy('postman_url', r'^sent/(?:(?P<option>m)/)?$'), SentView.as_view(), name='sent'),
# Translators: keep consistency of the <option> parameter with the translation for 'm'
url(pgettext_lazy('postman_url', r'^archives/(?:(?P<option>m)/)?$'), ArchivesView.as_view(), name='archives'),
# Translators: keep consistency of the <option> parameter with the translation for 'm'
url(pgettext_lazy('postman_url', r'^trash/(?:(?P<option>m)/)?$'), TrashView.as_view(), name='trash'),
url(pgettext_lazy('postman_url', r'^write/(?:(?P<recipients>[^/#]+)/)?$'), WriteView.as_view(), name='write'),
url(pgettext_lazy('postman_url', r'^reply/(?P<message_id>[\d]+)/$'), ReplyView.as_view(), name='reply'),
url(pgettext_lazy('postman_url', r'^view/(?P<message_id>[\d]+)/$'), MessageView.as_view(), name='view'),
# Translators: 't' stands for 'thread'
url(pgettext_lazy('postman_url', r'^view/t/(?P<thread_id>[\d]+)/$'), ConversationView.as_view(), name='view_conversation'),
url(pgettext_lazy('postman_url', r'^archive/$'), ArchiveView.as_view(), name='archive'),
url(pgettext_lazy('postman_url', r'^delete/$'), DeleteView.as_view(), name='delete'),
url(pgettext_lazy('postman_url', r'^undelete/$'), UndeleteView.as_view(), name='undelete'),
url(pgettext_lazy('postman_url', r'^mark-read/$'), MarkReadView.as_view(), name='mark-read'),
url(pgettext_lazy('postman_url', r'^mark-unread/$'), MarkUnreadView.as_view(), name='mark-unread'),
url(r'^$', RedirectView.as_view(url=reverse_lazy('postman:inbox'), permanent=True)),
]
寫.html
{% extends "postman/base_write.html" %}
{% load i18n %}
{% block pm_write_title %}{% trans "Write"%}{% endblock %}
base_write.html
{% extends "postman/base.html" %}
{% load i18n static %}
{% block extrahead %}{{ block.super }}
{% if autocompleter_app.is_active %}{# using the available admin jQuery is enough #}
{# should not be necessary since AS v1.3 with AJAX_SELECT_BOOTSTRAP set #}
{#<script type="text/javascript" src="{% static 'admin/js/jquery.min.js' %}"></script>#}
{% endif %}
{{ form.media }}{# for ajax_selects (v1.3.6 at least) #}
{% endblock %}
{% block content %}
<div id="postman">
<h1>{% block pm_write_title %}{% endblock %}</h1>
<form action="{% if next_url %}?next={{ next_url|urlencode }}{% endif %}" method="post">{% csrf_token %}
<table>
{% block pm_write_recipient %}{% endblock %}
{{ form.as_table }}
</table>
<button type="submit" class="pm_btn pm_btn-send">{% trans "Send" %}</button>
</form>
</div>
{% endblock %}
基本文件
{% extends "base.html" %}{# not myself but a site-level one (TEMPLATE_DIRS setting) #}
{% load i18n static %}{% load postman_tags %}
{% block title %}{% trans "Messaging" %}{% endblock %}
{% block extrahead %}{{ block.super }}
<link type="text/css" media="all" rel="stylesheet" href="{% static 'postman/css/postman.css' %}" />
{% endblock %}
{% block postman_menu %}
<ul id="postman_menu">{% postman_unread as unread_count %}
<li><a href="{% url 'postman:inbox' %}">» {% trans "Inbox" %}{% if unread_count %} <strong>({{ unread_count }})</strong>{% endif %}</a></li>
<li><a href="{% url 'postman:sent' %}">» {% trans "Sent Messages" %}</a></li>
<li><a href="{% url 'postman:write' %}">» {% trans "Write" %}</a></li>
<li><a href="{% url 'postman:archives' %}">» {% trans "Archives" %}</a></li>
<li><a href="{% url 'postman:trash' %}">» {% trans "Trash" %}</a></li>
</ul>
{% endblock %}
問題是,每當我在瀏覽器中運行 127.0.0.1:8000/messages/write 時,網站都是空白的。 django 管理員顯示消息框,但 url 返回空白。 我在這里做錯了什么。 謝謝
以下是讓您開始使用最低限度的步驟:
在根目錄(帶有manage.py
目錄) python3 -m pip install django-postman
在settings.py
:
INSTALLED_APPS = [
...,
# 'pagination' # has to be before postman
# ...
'postman',
# ...
# 'ajax_select'
# 'notification'
# 'mailer'
]
TEMPLATES = [
{
'...,
'DIRS': [BASE_DIR/ 'templates'],
...
},
]
在根目錄執行以下命令: python manage.py migrate
mkdir -p templates/postman
touch templates/postman/base.html
現在您應該能夠在您網站的管理頁面上看到Messages
和Pending
。
base.html
文件中:<!doctype html>
<html>
<head>
<title>
{% block title %}
{% endblock %}
</title>
{% block extrahead %}
{% endblock %}
</head>
<body>
{% block content %}
{% endblock %}
{% block postman_menu %}
{% endblock %}
</body>
</html>
這是因為包希望這個模板能夠呈現 url。 5.在項目的urlpatterns中添加這個路徑path:
path('messages/', include('postman.urls'), name='postman'),
現在您可以使用實際網站上的任何網址
localhost:8000/messages/write
有一個問題,默認情況下,您發送的消息將處於待處理狀態,因此您必須手動從管理站點(由主持人)批准,或者您可以在settings.py.
POSTMAN_AUTO_MODERATE_AS=True
settings.py.
上面的大部分內容在django-postman 文檔中都有提到,但是作為初學者,掌握這些對我來說非常具有挑戰性,所以我試圖簡化步驟,希望對某人有所幫助:)
您是否在 postman/base.html 擴展的 base.html 模板中包含了所需的模板塊?
來自: https : //bitbucket.org/psam/django-postman/wiki/quickstart#rst-header-templates
postman/base.html
模板擴展了base.html
站點模板,其中需要一些塊:
•title:在<html><head><title>
,至少是整個標題字符串的一部分
•extrahead:在<html><head>
,放置一些<script>
和<link>
元素
•content: 在<html><body>
,放置頁面內容
•postman_menu:在<html><body>
,放置導航菜單
其次是 Amiay Narayan 的回答,對 base.html 文件部分進行了一些修改。
來自 Django-postman 的最新 base.html 是:
{% extends "base.html" %}{# not myself but a site-level one (TEMPLATE_DIRS setting) #}
所以在你自己的 Django 項目的 base.html 中,唯一需要在 <body>.....</body> 之間添加的東西是 Django-postman 的簡單菜單:
{% block postman_menu %}
{% endblock %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.