【问题标题】:Is there a way I can make users to pay first before making a post on a Django website?有没有办法让用户在 Django 网站上发帖之前先付款?
【发布时间】:2021-09-30 05:56:41
【问题描述】:

这是我的模特

from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.urls import reverse


class Escort(models.Model):
    name = models.CharField(max_length=40)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    bio = models.TextField()
    phone = models.CharField(max_length=14)
    ethnicity = models.CharField(max_length=20)
    orientation = models.CharField(max_length=20)
    location = models.CharField(max_length=40)
    area = models.TextField()
    skin_color = models.CharField(max_length=40)
    hair_color = models.CharField(max_length=40)
    services = models.CharField(max_length=255)
    paid = models.BooleanField(default=False)

    def __str__(self):
        return self.name + '~' + str(self.author)

    def get_absolute_url(self):
        return reverse('escort-details', args=(str(self.id)))

这些是我的看法

from django.shortcuts import render
from django.views.generic import ListView, DetailView, CreateView
from .models import Escort



#def home(request):
    #return render(request, 'home.html',{})


class HomeView(ListView):
    model = Escort
    template_name = 'home.html'

class EscortDetailView(DetailView):
    model = Escort
    template_name = 'escort_details.html'

class AddEscortView(CreateView):
    model = Escort
    template_name = 'add_escort.html'
    fields = '__all__'

这些是我的网址

from django.urls import path
from . import views

from .views import HomeView, EscortDetailView, AddEscortView

urlpatterns = [
    #path('', views.home, name="home"),
    path('', HomeView.as_view(), name="home"),
    path('escort/<int:pk>', EscortDetailView.as_view(), name="escort-details"),
    path('postad/', AddEscortView.as_view(), name="add-escort"),
    
]

我还有四个模板用于四个视图

我所做的基本上是创建一个网站来宣传护送服务。我希望用户注册/登录并单击链接“PostAd”并被重定向到带有护送表单的页面。在填写所有护送信息(护送模式)后,用户需要先付款,然后广告/帖子才会出现在主页上(护送的 ul 将在主页中使用 HTML 进行组织)。谁能从这里给我建议?

【问题讨论】:

    标签: django django-models django-views django-forms django-templates


    【解决方案1】:

    如果您希望用户拥有一个帐户并登录,那么您需要authentication。如果您想限制用户可以查看和执行的操作,则需要权限。 Django为此提供了一个内置系统。

    这是一个示例教程:Django Tutorial Part 8: User authentication and permissions

    请注意,默认情况下,Django 的权限系统仅处理模型级别的权限,即。 e.例如,可以授予用户编辑模型类型的权限。如果您想拥有模型实例的权限,则需要查看对象级权限。

    【讨论】:

      猜你喜欢
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 2011-10-30
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      相关资源
      最近更新 更多