有没有办法让用户在 Django 网站上制作 post 之前先付款?
Is there a way I can make users to pay first before making a post on a Django website?
这是我的模型
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"),
]
四个视图我也有四个模板
我主要做的是创建一个网站来宣传伴游服务。我希望用户登录 up/sign 并单击 link“PostAd”,然后被重定向到带有护送表单的页面。填写所有陪同信息(陪同模式)后,用户将被要求先付款,然后advert/post出现在首页上线(ul的陪同人员将在首页中使用HTML组织).请问谁能给我点建议?
如果您想让用户拥有一个帐户并登录,那么您需要authentication。如果您想限制用户可以看到的内容和可以执行的操作,则需要权限。 Django为此提供了一个内置系统。
这是一个示例教程:Django Tutorial Part 8: User authentication and permissions
请注意,默认情况下 Django 的权限系统仅处理模型级权限,即。 e.例如,可以授予用户编辑模型类型的权限。如果您想拥有模型实例的权限,则需要查看对象级权限。
这是我的模型
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"),
]
四个视图我也有四个模板
我主要做的是创建一个网站来宣传伴游服务。我希望用户登录 up/sign 并单击 link“PostAd”,然后被重定向到带有护送表单的页面。填写所有陪同信息(陪同模式)后,用户将被要求先付款,然后advert/post出现在首页上线(ul的陪同人员将在首页中使用HTML组织).请问谁能给我点建议?
如果您想让用户拥有一个帐户并登录,那么您需要authentication。如果您想限制用户可以看到的内容和可以执行的操作,则需要权限。 Django为此提供了一个内置系统。
这是一个示例教程:Django Tutorial Part 8: User authentication and permissions
请注意,默认情况下 Django 的权限系统仅处理模型级权限,即。 e.例如,可以授予用户编辑模型类型的权限。如果您想拥有模型实例的权限,则需要查看对象级权限。