Django 邮递员不工作

2024-01-02

我尝试实施Django-postman用于用户到用户的消息传递系统。

我克隆了存储库并在我的settings.py and URLs.py文件也:

In 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 = '[email protected] /cdn-cgi/l/email-protection'  # 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 %}

基本写入.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 %}

基础.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 %}

问题是,每当我在浏览器中运行 127.0.0.1:8000/messages/write 时,该网站都是空白的。 django admin 显示消息框,但 url 返回空白。我在这里做错了什么。谢谢


以下是让您从最低限度开始的步骤:

  1. 在根目录上(带有manage.py) python3 -m pip install django-postman

  2. In settings.py :

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

    mkdir -p templates/postman

touch templates/postman/base.html

现在您应该能够看到Messages and Pending在您网站的管理页面上。

  1. 将以下标记添加到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('messages/', include('postman.urls'), name='postman'),
  1. 现在您可以使用实际网站上的任何网址

    localhost:8000/messages/write

有一个问题,默认情况下,您发送的消息将是pending因此,您必须手动从管理站点(由版主)批准,或者您可以设置POSTMAN_AUTO_MODERATE_AS=True in the settings.py.

上面的大部分内容已经在django-postman 文档 https://django-postman.readthedocs.io/en/latest/quickstart.html#examples,但是对于我作为初学者来说掌握这些是非常具有挑战性的,所以我尝试简化步骤,希望它可以帮助别人:)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Django 邮递员不工作 的相关文章

  • python 模拟第三方模块

    我正在尝试测试一些处理推文的类 我使用 Sixohsix twitter 来处理 Twitter API 我有一个类充当 Twitter 类的外观 我的想法是模拟实际的 Sixohsix 类 通过随机生成新推文或从数据库检索它们来模拟推文的
  • 如何使用 imaplib 获取“消息 ID”

    我尝试获取一个在操作期间不会更改的唯一 ID 我觉得UID不好 所以我认为 Message ID 是正确的 但我不知道如何获取它 我只知道 imap fetch uid XXXX 有人有解决方案吗 来自 IMAP 文档本身 IMAP4消息号
  • 通过列表理解压平列表列表

    我正在尝试使用 python 中的列表理解来展平列表 我的清单有点像 1 2 3 4 5 6 7 8 只是为了打印这个列表列表中的单个项目 我编写了这个函数 def flat listoflist for item in listoflis
  • 为什么Python的curses中escape键有延迟?

    In the Python curses module I have observed that there is a roughly 1 second delay between pressing the esc key and getc
  • djangorest框架更改主键以使用唯一字段

    我有一个模型叫做GameProfile 这是一对一的关系User模型 我用了HyperlinkedModelSerializer贯穿我所有的设计 For the GameProfile 用户字段应该是查询的主键 它是唯一的但我没有将其设置为
  • 使用 OLS 回归预测未来值(Python、StatsModels、Pandas)

    我目前正在尝试在 Python 中实现 MLR 但不确定如何将我找到的系数应用于未来值 import pandas as pd import statsmodels formula api as sm import statsmodels
  • 如何通过在 Python 3.x 上按键来启动和中断循环

    我有这段代码 当按下 P 键时会中断循环 但除非我按下非 P 键 否则循环不会工作 def main openGame while True purchase imageGrab if a sum gt 1200 fleaButton ti
  • 使用鼻子获取设置中当前测试的名称

    我目前正在使用鼻子编写一些功能测试 我正在测试的库操作目录结构 为了获得可重现的结果 我存储了一个测试目录结构的模板 并在执行测试之前创建该模板的副本 我在测试中执行此操作 setup功能 这确保了我在测试开始时始终具有明确定义的状态 现在
  • 将 2D NumPy 数组按元素相乘并求和

    我想知道是否有一种更快的方法 专用 NumPy 函数来执行 2D NumPy 数组的元素乘法 然后对所有元素求和 我目前使用np sum np multiply A B 其中 A B 是相同维度的 NumPy 数组m x n 您可以使用np
  • 如何在 python 中没有 csv.reader 迭代器的情况下解析单行 csv 字符串?

    我有一个 CSV 文件 需要重新排列和重新编码 我想跑 line line decode windows 1250 encode utf 8 在由 CSV 读取器解析和分割之前的每一行 或者我想自己迭代行 运行重新编码 并仅使用单行解析表单
  • Python 将日志滚动到变量

    我有一个使用多线程并在服务器后台运行的应用程序 为了无需登录服务器即可监控应用程序 我决定包括Bottle http bottlepy org为了响应一些HTTP端点并报告状态 执行远程关闭等 我还想添加一种查阅日志文件的方法 我可以使用以
  • python Soap zeep模块获取结果

    我从 SOAP API 得到如下结果 client zeep Client wsdl self wsdl transport transport auth header lb E authenticate self login res cl
  • 使用 NumPy 将非均匀数据从文件读取到数组中

    假设我有一个如下所示的文本文件 33 346 1223 10 23 11 23 12 23 13 23 14 23 15 23 16 24 10 24 11 24 12 24 13 24 14 24 15 24 16 25 14 25 15
  • 如何在 OSX 上安装 numpy 和 scipy?

    我是 Mac 新手 请耐心等待 我现在使用的是雪豹 10 6 4 我想安装numpy和scipy 所以我从他们的官方网站下载了python2 6 numpy和scipy dmg文件 但是 我在导入 numpy 时遇到问题 Library F
  • 默认情况下,Keras 自定义层参数是不可训练的吗?

    我在 Keras 中构建了一个简单的自定义层 并惊讶地发现参数默认情况下未设置为可训练 我可以通过显式设置可训练属性来使其工作 我无法通过查看文档或代码来解释为什么会这样 这是应该的样子还是我做错了什么导致默认情况下参数不可训练 代码 im
  • Tkinter - 浮动窗口 - 调整大小

    灵感来自this https stackoverflow com a 22424245 13629335问题 我想为我的根窗口编写自己的调整大小函数 但我刚刚注意到我的代码显示了一些性能问题 如果你快速调整它的大小 你会发现窗口没有像我希望
  • 迭代 my_dict.keys() 并修改字典中的值是否会使迭代器失效?

    我的例子是这样的 for my key in my dict keys my dict my key mutate 上述代码的行为是否已定义 假设my dict是一本字典并且mutate是一个改变其对象的方法 我担心的是 改变字典中的值可能
  • 当鼠标悬停在上面时,intellisense vscode 不显示参数或文档

    我正在尝试将整个工作流程从 Eclipse 和 Jupyter Notebook 迁移到 VS Code 我安装了 python 扩展 它应该带有 Intellisense 但它只是部分更糟糕 我在输入句点后收到建议 但当将鼠标悬停在其上方
  • Ubuntu 上的 Python 2.7

    我是 Python 新手 正在 Linux 机器 Ubuntu 10 10 上工作 它正在运行 python 2 6 但我想运行 2 7 因为它有我想使用的功能 有人敦促我不要安装 2 7 并将其设置为我的默认 python 我的问题是 如
  • 您可以将操作直接应用于map/reduce/filter 中的参数吗?

    map and filter通常可以与列表理解互换 但是reduce并不那么容易被交换map and filter 此外 在某些情况下我仍然更喜欢函数语法 但是 当您需要对参数本身进行操作时 我发现自己正在经历语法体操 最终必须编写整个函数

随机推荐