django-views

“object of type 'NoneType' has no len()” error

家住魔仙堡 提交于 2021-02-05 08:16:46
问题 Error: object of type 'NoneType' has no len() Error in Signupform validation in django def signup(request): print(request) if request.method == "POST": error_msg = None fname = request.POST.get('fname') lname = request.POST.get('lname') email = request.POST.get('email') password = request.POST.get('password') value = {'fname': fname, 'lname': lname, 'email':email} customer = Signup(first_name=fname, last_name=lname, email=email, password=password) if len(fname) < 4: error_msg = "First Name

How do I include my def clean_slug function into my views or template so that it will work and show “title alr exist”

送分小仙女□ 提交于 2021-02-05 08:12:41
问题 Hi I have written a def clean(self) function in forms to make sure that if there was previously already a post with the same title, they will return a message saying that the title already exists and hence the form cannot be submitted. Problem now: When I enter a title that already exists and I try to create the post, all data previously input will be removed and I will be redirected to a fresh form. No errors were raised. What I want is for the error to be raised and shown to the user when I

How do I include my def clean_slug function into my views or template so that it will work and show “title alr exist”

半城伤御伤魂 提交于 2021-02-05 08:11:34
问题 Hi I have written a def clean(self) function in forms to make sure that if there was previously already a post with the same title, they will return a message saying that the title already exists and hence the form cannot be submitted. Problem now: When I enter a title that already exists and I try to create the post, all data previously input will be removed and I will be redirected to a fresh form. No errors were raised. What I want is for the error to be raised and shown to the user when I

django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node

耗尽温柔 提交于 2021-02-04 21:36:15
问题 I'm trying to deploy my project on heroku ,i'm using django 3.1 and i'm unable to do that. I'm getting error due to migrations. Please i humble request you to give some time to this question to resolve this problem. Whenever i run the command heroku run python manage.py migrate ,it gives following traceback. Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/app/.heroku/python/lib

Django class view - MultipleObjectsReturned error

别说谁变了你拦得住时间么 提交于 2021-02-04 19:48:07
问题 I'm still new at django so please bear with me. I'm trying to make a website about books. Now I'm having error like this MultipleObjectsReturned at /premium/1/ get() returned more than one Book -- it returned 2! I don't know where to look for the error. Here is my example code. class PageDetailView(LoginRequiredMixin, generic.View): def get(self, request, *args, **kwargs): book = get_object_or_404(Book) page = get_object_or_404(Page) user_membership = get_object_or_404(Customer, user=request

Adapt an existing database to a django app

陌路散爱 提交于 2021-02-04 13:22:06
问题 I have a Postgresql databese with data. I want to create a django app with that database. How can i import the tables to django models and/or views? 回答1: There is a utility called manage.py inspectdb to generate models from your existing database. It works pretty well. $ python manage.py inspectdb > models.py 回答2: If your database is not very simple -- or very well designed -- you'll find it a poor fit with Django. While the reverse engineering works well, you may find that the original

Adding custom field to django-notifications always returning none on notify.send()

China☆狼群 提交于 2021-01-29 21:02:16
问题 I am trying to add a new field to the Notification model in django-notifications-hq. Currently in my main/models.py i have: class Notification(AbstractNotification): # custom field example unique_uuid = models.CharField(max_length=255,unique=True, null=True) class Meta(AbstractNotification.Meta): abstract = False app_label = 'main' Now in my settings.py file I have: NOTIFICATIONS_NOTIFICATION_MODEL = 'main.Notification' NOTIFICATIONS_USE_JSONFIELD=True I am trying to generate a notification

I want to edit SizeProductMapping model using Django forms but The form is not rendering - Django

断了今生、忘了曾经 提交于 2021-01-29 19:51:06
问题 I am trying to create a edit form to update the database using Django model Forms but the problem is that edit form part of the sizeProductMap.html page is not rendering when edit form ( sizeProductMap_edit ) request is made. My models are as shown below. models.py class Product(models.Model): prod_ID = models.AutoField("Product ID", primary_key=True) prod_Name = models.CharField("Product Name", max_length=30, null=False) prod_Desc = models.CharField("Product Description", max_length=2000,

Adding custom field to django-notifications always returning none on notify.send()

十年热恋 提交于 2021-01-29 18:31:29
问题 I am trying to add a new field to the Notification model in django-notifications-hq. Currently in my main/models.py i have: class Notification(AbstractNotification): # custom field example unique_uuid = models.CharField(max_length=255,unique=True, null=True) class Meta(AbstractNotification.Meta): abstract = False app_label = 'main' Now in my settings.py file I have: NOTIFICATIONS_NOTIFICATION_MODEL = 'main.Notification' NOTIFICATIONS_USE_JSONFIELD=True I am trying to generate a notification

How to solve method not allowed (Post) http error 405

 ̄綄美尐妖づ 提交于 2021-01-29 18:05:51
问题 Codes in views I am new to django I couldn't able to rectify where it went wrong can anyone please help me on this. class UpdateVote(LoginRequiredMixin,UpdateView): form_class = VoteForm queryset = Vote.objects.all() def get_object(self,queryset=None): vote = super().get_object(queryset) user = self.request.user if vote.user != user: raise PermissionDenied('can not change another user vote') return vote def get_success_url(self): movie_id = self.object.movie.id return reverse('core:movie