私信  •  关注

Bidhan Majhi

Bidhan Majhi 最近创建的主题
Bidhan Majhi 最近回复了
5 年前
回复了 Bidhan Majhi 创建的主题 » django,路径/url

根据你的代码,所有的路径都是, http://127.0.0.1:8000/index/1/ http://127.0.0.1:8000/index/ http://127.0.0.1:8000/1/1/ http://127.0.0.1:8000/1/

与views.py中的轮询相关联的两个url是 http://127.0.0.1:8000/index/1/ http://127.0.0.1:8000/1/1/

正如你在标题中提到的 http://127.0.0.1:8000/index/1/ 工程和 http://127.0.0.1:8000/1/ 不是因为您请求了错误的url。您请求的URL不是视图的URL。轮询将其更改为 http://127.0.0.1:8000/1/1/ .你会得到你想要的结果。

在你的urlpatterns中,你有,

urlpatterns = [
  ...
]  + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

这意味着静态URL必须是路径,静态根是目录,但是在您的Stest.Py中,静态根被设置为“/static /”,这是错误的。

这是你能做的,

  1. 从urlpatterns中同时删除静态根目录、静态文件目录和 + static(...) 是的。并在模板中添加负载静态,这将正确工作。

  2. 添加StasyOrthOrth.OS.Puto.Soin(BaseIddir,static) StasyTURLUR=

    然后添加 +静态(…) 加入urlpatterns。

尽管你不需要做第二个。第一个可以用。

5 年前
回复了 Bidhan Majhi 创建的主题 » django updateview:valueerror:int()的文本无效,基数为10:username

试试这个

class UpdateProfileView(LoginRequiredMixin, UpdateView):
    login_url = '/add login link/'
    redirect_field_name = 'add login field'
    model = Profile
    success_url = reverse_lazy('home')
    form_class = update_profile_form
    template_name = 'update_profile.html'

   # add post function if you have

在HTML中,

<a href="{% url 'update_profile' profile.user.pk %}">UpdateProfile</a>

在URL中,

path('updateProfile/<int:pk>/', views.UpdateProfileView.as_view(), name='update_profile'),
5 年前
回复了 Bidhan Majhi 创建的主题 » 在django rest框架中添加注释字段的最佳方法

这是我的建议,

  1. 创建一个评论模型,

  2. 使用f.k添加用户模型。 user = models.ForeignKey(User, on_delete=models.CASCADE,) #可以根据需要添加空

  3. 添加带有F.K.的物品模型, article = models.ForeignKey(Article, on_delete=models.CASCADE, related_name='articlecomment')

  4. 使用auto_now_add=true添加日期

用户可以在这里添加任意数量的评论。