简体   繁体   English

Django-邮递员不工作

[英]Django-postman not working

I tried to implement Django-postman for the user to user messaging system.我试图为用户到用户的消息传递系统实现Django-postman

I cloned the repo and did this in my settings.py and URLs.py file too:我克隆了 repo 并在我的settings.pyURLs.py文件中也这样做了:

In URLs.py of main file i have included :在主文件的URLs.py ,我包含了:

 re_path(r'^messages/', include('postman.urls', namespace='postman')),

In Settings.py file I have included:在 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'

URLs of postman:邮递员网址:

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写.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基本文件

{% 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' %}">&raquo;&nbsp;{% trans "Inbox" %}{% if unread_count %} <strong>({{ unread_count }})</strong>{% endif %}</a></li>
 <li><a href="{% url 'postman:sent' %}">&raquo;&nbsp;{% trans "Sent Messages" %}</a></li>
 <li><a href="{% url 'postman:write' %}">&raquo;&nbsp;{% trans "Write" %}</a></li>
 <li><a href="{% url 'postman:archives' %}">&raquo;&nbsp;{% trans "Archives" %}</a></li>
 <li><a href="{% url 'postman:trash' %}">&raquo;&nbsp;{% trans "Trash" %}</a></li>
</ul>
{% endblock %}

The problem is that whenever I run 127.0.0.1:8000/messages/write in my browser, the website is blank.问题是,每当我在浏览器中运行 127.0.0.1:8000/messages/write 时,网站都是空白的。 The django admin shows messaging boxes but the url returns blank. django 管理员显示消息框,但 url 返回空白。 What am i doing wrong here.我在这里做错了什么。 Thanks谢谢

Below are the steps that will get you started with bare-minimum:以下是让您开始使用最低限度的步骤:

  1. On the root directory (directory with manage.py ) python3 -m pip install django-postman在根目录(带有manage.py目录) python3 -m pip install django-postman

  2. In settings.py :settings.py

INSTALLED_APPS = [ 
    ...,
    # 'pagination'  # has to be before postman
    # ...
    'postman',
    # ...
    # 'ajax_select'
    # 'notification'
    # 'mailer'
]
    
TEMPLATES = [
    {
        '...,
        'DIRS': [BASE_DIR/ 'templates'],
        ...
    },
]
  1. On the root directory execute the following command: python manage.py migrate在根目录执行以下命令: python manage.py migrate

    mkdir -p templates/postman

touch templates/postman/base.html

Now you should be able to see the Messages and Pending on the admin page of your site.现在您应该能够在您网站的管理页面上看到MessagesPending

  1. Add the following markup to the base.html file we created in the above step:将以下标记添加到我们在上述步骤中创建的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>

This is because the package expects this template to be able to render the urls.这是因为包希望这个模板能够呈现 url。 5. Add this path path to the project's urlpatterns: 5.在项目的urlpatterns中添加这个路径path:

path('messages/', include('postman.urls'), name='postman'),
  1. Now you can use any of the urls on the actual site现在您可以使用实际网站上的任何网址

    localhost:8000/messages/write

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.有一个问题,默认情况下,您发送的消息将处于待处理状态,因此您必须手动从管理站点(由主持人)批准,或者您可以在settings.py. POSTMAN_AUTO_MODERATE_AS=True settings.py.

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-postman 文档中都有提到,但是作为初学者,掌握这些对我来说非常具有挑战性,所以我试图简化步骤,希望对某人有所帮助:)

Did you include the required template blocks in YOUR base.html template that the postman/base.html is extending?您是否在 postman/base.html 扩展的 base.html 模板中包含了所需的模板块?

From: https://bitbucket.org/psam/django-postman/wiki/quickstart#rst-header-templates来自: https : //bitbucket.org/psam/django-postman/wiki/quickstart#rst-header-templates

The postman/base.html template extends a base.html site template, in which some blocks are expected: postman/base.html模板扩展了base.html站点模板,其中需要一些块:
•title: in <html><head><title> , at least for a part of the entire title string •title:在<html><head><title> ,至少是整个标题字符串的一部分
•extrahead: in <html><head> , to put some <script> and <link> elements •extrahead:在<html><head> ,放置一些<script><link>元素
•content: in <html><body> , to put the page contents •content: 在<html><body> ,放置页面内容
•postman_menu: in <html><body> , to put a navigation menu •postman_menu:在<html><body> ,放置导航菜单

Second the answer from Amiay Narayan, with some modifications on the base.html file part.其次是 Amiay Narayan 的回答,对 base.html 文件部分进行了一些修改。

The latest base.html from the Django-postman is:来自 Django-postman 的最新 base.html 是:

{% extends "base.html" %}{# not myself but a site-level one (TEMPLATE_DIRS setting) #}

So in the base.html of your own Django project, the only thing that needs to be added somewhere between the <body>.....</body> is Django-postman's simple menu:所以在你自己的 Django 项目的 base.html 中,唯一需要在 <body>.....</body> 之间添加的东西是 Django-postman 的简单菜单:

    {% block postman_menu %}
    {% endblock %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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