我今天写的一个简单的例子:
class Grandparent(models.Model):
text = models.CharField(max_length=5, choices=too_many)
class Parent(models.Model):
grandparent = models.ForeignKey(Grandparent, on_delete=models.CASCADE)
info = models.CharField(max_length=30)
class ChildSomething(models.Model):
paren
每次我运行django项目时,我都会得到这个错误NoReverseMatch at / Reverse for 'product_list_by_category' with keyword arguments '{'slug': 'legume'}'。我想列出我的产品,老实说,我甚至不知道问题出在哪里。
完全跟踪: django.urls.exceptions.NoReverseMatch:用关键字参数“{‘s’:'legume'}‘找不到'product_list_by_category’。1模式尝试:
我的应用程序中出现了以下错误(就我在Google上看到的情况而言,这是很常见的):
Caught NoReverseMatch while rendering: Reverse for 'add-post' with arguments '()' and keyword arguments '{}' not found.
问题是我是第一次使用反向urls,所以我对可能导致这个错误的原因有点迷惑,显然我一切都好。有人能告诉我发生了什么事吗?
urls.py文件
urlpatterns = patterns('e_cidadania.apps
我是一个Django开发人员,有一个快速的问题。我有下面的代码,在其中我创建了一个模型'Plan',它有几个字段,我还为它创建了一个视图。但是,当我为create视图提交表单时,我会收到一个错误,说明它找不到可以重定向到的url。我尝试将'get_absolute_url‘方法添加到模型中,我也尝试将'success_url’属性添加到create视图中,但我总是得到以下错误:The view work.views.PlansCreateView didn't return an HttpResponse object. It returned None
我正在尝试设置一个Django站点(OSQA),但它无法工作。
有几个问题,其中一个问题是,当我试图查看用户的配置文件时,我得到了以下例外:
有人能指出问题出在哪里吗?
TemplateSyntaxError at /users/2/allenq/
Caught NoReverseMatch while rendering: Reverse for 'ask_to_me' with arguments '(2, u'allenq')' and keyword arguments '{}' not found.
Request Me
我正在学习Django,我有一个基本模型:
from django.db import models
class Country(models.Model):
name = models.CharField(max_length=255,)
continent = models.ForeignKey('Continent')
class Continent(models.Model):
name = models.CharField(max_length=255, unique = True)
countries = ???
我希望Conti
对于kwargs,我得到一个空字符串的NoReverseMatch错误。我是不是在models.py文件中做了什么不保存与帖子相关的用户名的错误?
NoReverseMatch at /group/post/in/nasa-rocks/反向表示“for_user”的关键字参数{“用户名”:“}”未找到。尝试了1种模式:[‘post/by/(?P^/+)/$’]
models.py:
from django.db import models
from django.urls import reverse
from django.conf import settings
# Create
我正在尝试使用django-simple-history来保持对象的状态。 假设我有以下内容: class Parent(models.Model):
fields...
history = HistoricalRecords(inherit=True)
class Child(Parent):
fields...
class Invoice(models.Model):
fields...
parent_history = models.ForeignKey("app.HistoricalParent", blank=True,
我是django的初学者。我有一个基于类的删除视图的问题,因为它返回一个没有反向匹配的错误。在url的末尾有一个美元符号,我没有提供。 这是错误: NoReverseMatch at /posts/myhome/
Reverse for 'delete_post' with no arguments not found. 1 pattern(s) tried: ['posts/(?P<slug>[^/]+)/delete$'] views.py class DeletePostView(BSModalDeleteView, LoginRequire
当我试图在数据库中创建一个新的django模型时,我得到了这个错误 AttributeError at /api/problemset/create
Got AttributeError when attempting to get a value for field `choice_option_set` on serializer `QuestionSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Question` instanc
我想在var标记中获取文本,它位于伪类:::before ... <var class="added">Element</var> .. ::after中。
我尝试了,也尝试了一些常见的方法,比如:
x = driver.find_elements_by_class_name("added")
elem = [i.text for i in x]
或者试图通过父元素访问它。因此,我总是得到一个空的列表。这里有人知道我做错了什么吗?
非常感谢!
我正在遵循Django注册的入门指南,在访问http://localhost:8080/accounts/register/时会遇到以下错误:
NoReverseMatch at /accounts/register/
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://localhost:8080/accounts/register/
Django Vers
我正在尝试用Django做一个LMS系统,现在我需要上传多个pdf文件到课程中。在Django模型中,我可以上传一个带有OnetoOne字段的文件,但不能上传更多。当我尝试为同一个类添加另一个材料时,它会显示Upload materials with this Uploaded class already exists.,这是我的模型代码。 class UploadMaterials(models.Model):
name = models.CharField(max_length=255)
uploaded_class = models.OneToOneField(Clas
当我刷新页面或提交回button..to时,我会得到一个表单重新提交错误--在post请求之后,我会将它重定向到一个显示实际page...when的新页面.单击mainpge.html上的submit按钮后,得到下面的错误
错误: NoReverseMatch在/startpage/
Reverse for 'testpage' with arguments '()' and keyword arguments '{}' not found.
views.py
from django.shortcuts import render_to_resp
Django-allauth包创建一个模型SocialAccount,向用户提供一个ForeignKey。我无法在我的查询集中预先获取这个信息。
我的模特:
class Placerating(models.Model):
author = models.ForeignKey('auth.User', null=True, on_delete=models.SET_NULL)
Django-allauth模型:
class SocialAccount(models.Model):
user = models.ForeignKey(allauth.app_sett
目前我有一个网站,我希望用户能够看到他们喜欢的文章。我希望这包括在已经设置的用户api视图中。我已经尝试过在drf文档中的tracks = serializers.StringRelatedField(many=True),但是这没有起作用。我还尝试了以下几点:
from rest_framework import serializers
from articles.models import Article, CustomUser,FavoriteArticles
class ArticleSerializer(serializers.ModelSerializer):
几天前,我完成了Django教程,并开始重新介绍我的应用程序中的功能。在我的models.py中,我偶然发现了一种方法,kwargs之类的东西对我来说不是很清楚。这背后的逻辑是什么,你能向我解释一下它的作用吗?谢谢。
models.py
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
class Creation(models.Model):
title =
我做了一个名为trydjango的项目,在这里我可以访问我用products/<int:my_id> [name='product']链接创建的产品,但不知怎么的,它不起作用,我找不到错误。打开http://127.0.0.1:8000/products/1/时,会得到一个404页未找到的错误,如下所示
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/products/1/
Using the URLconf defined in trydjango.url