我正在建立一个网站,我试图创建一个自定义的用户到用户消息传递系统,所以我安装了django-messages和其他一些东西,突然当我尝试运行我的服务器时,我收到以下错误:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\registry.py", …Run Code Online (Sandbox Code Playgroud) 我正在为我的网站建立一个评级系统。它目前运行良好,但我想改进系统的美观方面。我希望能够从数据库中获取评级并将其显示为 5 星级评级。另外,如果不是太复杂,我希望能够点击星星来将评级记录在数据库中,而不是写一个数字。
\n\n我对网络开发还很陌生。特别是,我没有使用 javascript 的经验(我只做过在互联网上找到的教程),我认为这是实现我正在搜索的功能所必需的,所以请给我一个小例子和你的回复,以便让我能够理解。
\n\n为了将评级渲染为星级,我不知道该怎么做。为了将评级记录为星级,我想到了两种解决方案:
\n\n1)使用django 星级评级,但我不认为我有能力理解它是如何工作的。我已经发帖寻求有关此应用程序的帮助和示例,但我没有收到任何帮助,所以我想我应该忘记这一点。
\n\n2) 使用带有适当小部件的表单将 IntegerInput 呈现为 5 星评级。
\n\n对于第二个解决方案,我已经有了代码,我现在需要一个小部件来替换\'Stars\'下面的代码,但我不知道该怎么做。有人能帮我吗 ?
模型.py
\n\nclass Avis(models.Model):\n note = models.IntegerField()\nRun Code Online (Sandbox Code Playgroud)\n\n表格.py
\n\nclass AvisForm(forms.ModelForm):\n class Meta:\n model = Avis\n fields = [\'note\']\n widgets = {\'note\': forms.NumberInput(attrs={\'class\': \'Stars\'})}\n labels = {\'note\': \'Note /5\'}\nRun Code Online (Sandbox Code Playgroud)\n\n用于记录的 hmtl
\n\n<form method="post" action="">\n {% csrf_token %}\n {% for field in form %}\n <div class="fieldWrapper form-group">\n {{ field.label_tag }}\n {{ …Run Code Online (Sandbox Code Playgroud) 在我的模板中加载自定义标签时出现此错误。我访问了许多关于此的主题,并且确保确认我没有犯一些常见错误:
templatetags文件位于文件夹中。templatetags文件夹包含一个__init__.py文件。actualites位于INSTALLED_APPS设置列表中。{% load mes_tags %}模板的开头使用。这是我的应用程序的文件结构:
actualites/
__init__.py
SOME FILES
templatetags/
__init__.py
mes_tags.py
Run Code Online (Sandbox Code Playgroud)
mes_tags.py
from django import template
register = template.Library()
@register.simple_tag(takes_context=True)
def param_replace(context, **kwargs):
d = context['request'].GET.copy()
for k, v in kwargs.items():
d[k] = v
for k in [k for k, v in d.items() if not v]:
del d[k]
return d.urlencode()
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
TemplateSyntaxError at /
'mes_tags' is not a registered tag library. Must be …Run Code Online (Sandbox Code Playgroud)