__ init __()接受1个位置参数,但在对标记添加Latex支持时给出了2个位置参数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了__ init __()接受1个位置参数,但在对标记添加Latex支持时给出了2个位置参数相关的知识,希望对你有一定的参考价值。

我正在关注此tutorial,以将LaTeX支持添加到降价,但出现此错误:

环境:

请求方法:GET请求URL:http://localhost/posts/ttttt/

Django版本:2.2.10 Python版本:3.7.3已安装的应用程序:[“首页”,“搜索”,“信息”,“列表”,“信息流”,“发布”,“常见问题”,'registration','snippet','wagtailmd','wagtailcodeblock','wagtail.contrib.forms','wagtail.contrib.redirects','wagtail.embeds','wagtail.sites','wagtail.users','wagtail.snippets','wagtail.documents','wagtail.images','wagtail.search','wagtail.admin','wagtail.core','wagtail.contrib.modeladmin','wagtail.contrib.styleguide','modelcluster','taggit','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django.contrib.sites','django.contrib.humanize','allauth','allauth.account','allauth.socialaccount','crispy_forms','wagtailmenus','captcha','wagtailcaptcha']已安装的中间件:['django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','django.middleware.security.SecurityMiddleware','wagtail.core.middleware.SiteMiddleware','wagtail.contrib.redirects.middleware.RedirectMiddleware']

模板错误:在模板中C:\ Users \ abdom \ OneDrive \ Desktop \ project \ website \ templates \ base.html,第0行的错误init()接受1个位置参数,但有2个给定1:%load static wagtailuserbar% 2:%load menu_tags% 3:4:5:6:7:8:9:%块标题% 10:%如果self.seo_title% self.seo_title %else% self.title %endif%

追踪:

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ core \ handlers \ exception.py”在内部34. response = get_response(request)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ wagtail \ core \ models.py”在_get_response中1254. response = response.render()

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ response.py”在渲染106. self.content = self.rendered_content

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ response.py”在render_content中83. content = template.render(context,self._request)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ backends \ django.py”在渲染61. return self.template.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在渲染171. return self._render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在_render中163.返回self.nodelist.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在渲染937。位= node.render_annotated(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在render_annotated中904. return self.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ loader_tags.py”在渲染150.返回created_pa​​rent._render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在_render中163.返回self.nodelist.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在渲染937。位= node.render_annotated(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在render_annotated中904. return self.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ loader_tags.py”在渲染62.结果= block.nodelist.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在渲染937。位= node.render_annotated(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在render_annotated中904. return self.render(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”在渲染987。输出= self.filter_expression.resolve(context)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ django \ template \ base.py”决心698. new_obj = func(obj,* arg_vals)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project \ wagtailmd \ templatetags \ wagtailmd.py”在markdown_filter中14. output_format ='html5'

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ markdown \ core.py”降价387. md = Markdown(** kwargs)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ markdown \ core.py”在init中97. configs = kwargs.get('extension_configs',))

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ markdown \ core.py”在registerExtensions中123. ext = self.build_extension(ext,configs.get(ext,))

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project.venv \ lib \ site-packages \ markdown \ core.py”在build_extension中178. return module.makeExtension(** configs)

文件“ C:\ Users \ abdom \ OneDrive \ Desktop \ project \ wagtailmd \ mdx \ mdx_mathjax.py”在makeExtension中23.返回MathJaxExtension(configs)

异常类型:/ posts / ttttt处的TypeError /异常值:init()接受1个位置参数,但给出了2个]

mdx_mathjax.py:

import markdown
import cgi

class MathJaxPattern(markdown.inlinepatterns.Pattern):
    def __init__(self, md):
        markdown.inlinepatterns.Pattern.__init__(
            self, r'(?<!\\)(\$\$?)(.+?)\2', md)

    def handleMatch(self, m):
        # Pass the math code through, unmodified except for basic entity 
        # substitutions. 
        # Stored in htmlStash so it doesn't get further processed by Markdown.
        text = cgi.escape(m.group(2) + m.group(3) + m.group(2))
        return self.markdown.htmlStash.store(text)

class MathJaxExtension(markdown.Extension):
    def extendMarkdown(self, md, md_globals):
        # Needs to come before escape matching because \ is pretty important
        # in LaTeX
        md.inlinePatterns.add('mathjax', MathJaxPattern(md), '<escape')

def makeExtension(configs=[]):
    return MathJaxExtension(configs)

wagtailmd.py:

import markdown
from django import template

register = template.Library()

@register.filter(name='markdown')
def markdown_filter(value):
    return markdown.markdown(
    value,
    extensions=[
        'wagtailmd.mdx.mdx_mathjax',
    ],
    output_format='html5'
)

我的post_page.html

% extends 'base.html' %
% load static %

% load wagtailcore_tags wagtailimages_tags wagtailmd %


% block content %

<!-- main -->

<main>
    <div class="uk-container uk-container-small" style="margin: 0 auto;">

        <article>
            <div class="math-editor">
                 self.math_editor|markdown|safe 
            </div>
        </article>
    </div>
</main>

<!-- /main -->

% endblock content %

% block extra_js %
<script type="text/x-mathjax-config">
    MathJax.Hub.Config(
      extensions: ["tex2jax.js"],
      jax: ["input/TeX", "output/HTML-CSS"],
      tex2jax: 
        inlineMath: [['$','$']],
        displayMath: [['$$','$$']] ,
        processEscapes: true
      ,
      "HTML-CSS":  availableFonts: ["TeX"] 
    );
  </script>

  <script type="text/javascript"
     src="//cdn.mathjax.org/mathjax/latest/MathJax.js">
  </script>
% endblock %

谢谢。

答案

您的代码中存在实现错误。根据markdowndocumentation,应定义要为自定义Extension提供的参数。

以上是关于__ init __()接受1个位置参数,但在对标记添加Latex支持时给出了2个位置参数的主要内容,如果未能解决你的问题,请参考以下文章

简单的留言簿 django:__init__() 接受 1 个位置参数,但给出了 2 个

TypeError: __init__() 接受 1 个位置参数,但给出了 3 个

图表类:TypeError:__init__() 接受 1 个位置参数,但给出了 3 个

__init__() 接受 1 到 2 个位置参数,但给出了 3 个

TypeError: __init__() 接受 2 个位置参数,但给出了 4 个

TypeError: __init__() 接受 2 个位置参数,但给出了 3 个 // 链接列表 [重复]