Django的邮递员不工作 [英] Django-postman not working
问题描述
我试图为用户到用户消息传递系统实现 Django-postman
.
I tried to implement Django-postman
for the user to user messaging system.
我克隆了该存储库,并在我的 settings.py
和 URLs.py
文件中进行了此操作:
I cloned the repo and did this in my settings.py
and URLs.py
file too:
在主文件的 URLs.py
中,我包括了:
In URLs.py
of main file i have included :
re_path(r'^messages/', include('postman.urls', namespace='postman')),
在我包含的Settings.py文件中:
In Settings.py file I have included:
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)),
]
Write.html
Write.html
{% extends "postman/base_write.html" %}
{% load i18n %}
{% block pm_write_title %}{% trans "Write"%}{% endblock %}
base_write.html
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 %}
Base.html
Base.html
{% 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返回空白.我在这里做错了什么.谢谢
The problem is that whenever I run 127.0.0.1:8000/messages/write in my browser, the website is blank. The django admin shows messaging boxes but the url returns blank. What am i doing wrong here. Thanks
推荐答案
以下是使您从最小开始的步骤:
Below are the steps that will get you started with bare-minimum:
-
在根目录上(具有
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 migration
mkdir -p模板/邮递员
触摸模板/postman/base.html
现在,您应该可以在网站的管理页面上看到消息
和待处理
.
Now you should be able to see the Messages
and Pending
on the admin page of your site.
- 将以下标记添加到我们在以上步骤中创建的
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:
This is because the package expects this template to be able to render the urls. 5. Add this path path to the project's urlpatterns:
path('messages/', include('postman.urls'), name='postman'),
-
现在您可以在实际网站上使用任何网址
Now you can use any of the urls on the actual site
localhost:8000/messages/write
有一个陷阱,默认情况下,您发送的邮件将为 待处理 ,因此您必须手动从管理站点(由主持人)批准,或者您可以设置 settings.py中的
POSTMAN_AUTO_MODERATE_AS = True
.
There is one catch, by default the messages that you send will be pending so either you have to approve from the admin site ( by moderator) manually or you can set the
POSTMAN_AUTO_MODERATE_AS=True
in the settings.py.
在 django-postman文档中提到了以上大多数内容,但对于初学者来说,要掌握这些内容非常具有挑战性,所以我尝试简化步骤,希望对您有所帮助:)
Most of the above have been mentioned in django-postman documentation, but it was very challenging for me as a beginner to grasp these, So I have tried to simplify the steps, Hope it helps someone :)
这篇关于Django的邮递员不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!