Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
django.db.utils.DataError: (1406, "Data too long for column 'password' at row 1")
In my Django projects makemigrations and migrate work fine. But then I try to create a superuser and I get this error: django.db.utils.DataError: (1406, "Data too long for column 'password' at row 1") Does anybody know why that is? The password I use has 9 characters, 4 of which are numbers and the rest letters, so that shouldn't be a problem. -
Why is my javascript method not being called?
I have this in my HTML body: <script src="{% static "jquery/sessionExists.js" %}"></script> {% if context.alreadyOnSession == 'YES' %} <h5 class="loginerror" onload="advSessionExists()">This session is already logged in</h5> {% endif %} These {} are django code. JavaScript: function advSessionExists(){ console.log('Just checking if its triggered'); } Also I tried by putting my JavaScript code raw in the HTML body with <script type=text/javascript></script>, and also I tried with onbeforeprint instead of onload but it is still not showing my JS method. The <h5> is being showed, but not triggering my JS method. -
Django - For loop for two variables passed in a dictionary
In my view.py file I have two queries, each assigned a variable name. Query 1 collects all of the reviews in the reviews table. Query 2 calculates the average rating for each review from the reviews table. Two queries, one table. I've placed Query 1 (named reviews) and Query 2 (named ratings) inside of a dictionary named context to be passed to my html file. My goal is to show each review and that review's rating. However I'm having trouble displaying it properly with my current approach. Here's my html file: {% extends "reviews/layout.html" %} {% block content %} {% for review in reviews %} {% for rating in ratings %} <article class="media content-section"> <img class="rounded-circle article-img" src="{{ review.author.profile.image.url }}"> <div class="media-body"> <div class="article-metadata"> <h4 class="mr-2">{{ review.company }} {{ rating.rate }}</h4> <small class="text-muted">{{ review.date_posted|date:"F d, Y" }}</small> </div> <h5><a class="article-title" href="{% url 'review-detail' review.id %}">{{ review.title }}</a></h5> <p class="article-content">{{ review.content }}</p> </div> </article> {% endfor %} {% endfor %} {% endblock content %} I have a for loop within a for loop. As expected, the result is for each review is being display over and over again for each average. For example, I have 7 reviews with 7 ratings. The … -
Django admin: How to redirect to child's model's view from parent?
I have two django models that are registered with the admin. Let us consider an example below : #parent class Manufacturer(models.Model): name = models.TextField() #some relevant fields ... #child class Car(models.Model): models.ForeignKey(Manufacturer, on_delete=models.CASCADE, related_name="manufacturers) # some relevant fields Both these models are registered with the admin. So in the admin view the list for Manufacturer is displayed. Now I want that if someone clicks on the manufacturer name, it should redirect to the car's list with all those car's listed who has that Manufacturer as parent. Is it possible to achieve this? If so, how? -
Save a shell cmd output to django user field
i'm using electrum as a Bitcoin wallet for my application and now i want to allocate addresses from this wallet to a user if he requests a new one. Therefor i got 2 views. the first is for showing the wallet and the second one is for allocating a new btc address to the users account trough subprocess im calling the acctual cmd but how to save it properly? currently i get the following error: DoesNotExist at /user/wallet_deposit/new_addr_btc User matching query does not exist. views.py def wallet_deposit(request, pk=None): if pk: user = get_user_model().objects.get(pk=pk) else: user = request.user args = {'user': user} return render(request, 'MyProject_Accounts/wallet_deposit.html', args) def wallet_deposit_gen_new_addr_btc(request, pk=None): if request.method == 'GET': user = get_user_model().objects.get(pk=pk) new_address = subprocess.Popen(['electrum', 'createnewaddress']) try: user = user.objects.update_or_create(acc_btc_addr=new_address) user.save() except: messages.WARNING("Uups, something went wrong while allocating a new BTC address, please try again or contact the support.") else: user = request.user args = {'user': user} return render(request, 'MyProject_Accounts/wallet_deposit.html', args) -
Showing data reletaed to a logged in user in django
Hello am building this simple system for a school.Where students can log in to see their results at the end of every semester.I designed a model for exams with a manytomany relationship to a user.My problems is in my template am finding it hard to show a exams results related to a logged in user. your help will be really appreciated.Thank You model.py class StudentProfile(models.Model): SEX_CHOICES = ( ('Male', 'Male'), ('Female', 'Female') ) user = models.OneToOneField(User, on_delete=models.CASCADE) level = models.ForeignKey('Level', null=True, blank=True, on_delete=models.CASCADE) other_name = models.CharField(max_length=30, null=True, blank=True) birth_of_date = models.DateField(null=True, blank=True) birth_Of_admission = models.DateField(null=True, blank=True) nationality = models.CharField(max_length=120) phone_number = models.CharField(max_length=15, validators=[MinLengthValidator(10)]) gender = models.CharField(max_length=120, choices=SEX_CHOICES) home_address = models.CharField(max_length=250, null=True, blank=True, ) passport_picture = models.ImageField(upload_to='passport_picture', null=True, blank=True, help_text='Upload the passport picture here') def __str__(self): return "%s %s" % (self.user.first_name, self.user.last_name) @receiver(post_save, sender=User) def create_or_update_user_profile(sender, instance, created, **kwargs): if created: StudentProfile.objects.create(user=instance) instance.studentprofile.save() class Subject(models.Model): subject_name = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.subject_name class Year(models.Model): year = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.year class Exam(models.Model): TERM_CHOICES = ( ('First Term', 'First Term'), ('Second Term', 'Second Term'), ('Third Term', 'Third Term') ) student = models.ManyToManyField(User) year = models.ForeignKey(Year, null=True, blank=True, on_delete=models.CASCADE) subject = models.ForeignKey(Year, null=True, blank=True, on_delete=models.CASCADE) term = models.CharField(max_length=120, … -
How to access and configure postgresql database from python django on Windows 7 using a command CMD
""" When I run a CMD Windows 7 command "python manage.py makemigrations" I get an error "django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend. Try using 'django.db.backends.XXX' where XXX is one of : 'mysql', 'oracle', 'sqlite3' I have installed postgresql 10, and in my django setting.py I have set the postgresql as per the documentation on https://docs.djangoproject.com/en/2.1/ref/databases/ I want to access postgresql database from python django app using CMD on Windows 7. I'm using Windows 7, python 3.7.1; postgresql 10; django 2.1.5. I've tried several searches for solution but I do not get a relevant solution. I have already created my postgresql database using pgAdmin 4 v4 but it fails to be accessed using CMD command on Windows 7 to do commands like python manage.py showmigrations/makemigrations/migrate all sends the same error as presented in the subject. """ settings.py file starts here... """ Django settings for my_sample project. Generated by 'django-admin startproject' using Django 2.1.5. For more information on this file, see https://docs.djangoproject.com/en/2.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.1/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # … -
Resize Django login form?
Im trying to resize the width of my Django username and password login form so that they take up the full width of the log in container. However, non of the usual CSS properties seem to be resizing the forms. Is there something that I'm missing when it comes to resizing Django AuthenticationForms? See picture below: My HTML: <form class="log_in_form" action="{% url 'inventory_management_app:login' %}" method="post"> <p> {% csrf_token %} {{ form.username }} </p> <br> <p> {{ form.password }} <br> <p> </p> <br> {% if form.errors %} <p>Username or password is not correct</p> {% endif %} </p> <p> <br> <input id="search-button" class="btn btn-dark" type="submit" value="Login"> </form> My forms.py: from django import forms from django.contrib.auth.forms import AuthenticationForm from django.forms.widgets import PasswordInput, TextInput class CustomAuthForm(AuthenticationForm): username = forms.CharField(widget=TextInput(attrs={'class':'validate','placeholder': 'Email'})) password = forms.CharField(widget=PasswordInput(attrs={'placeholder':'Password'})) My CSS: .log_in_form { width: 100%; } -
SMTPSenderRefused at /password-reset/
I am set a gmail account to send emails to reset password. but i get this error.please help SMTPSenderRefused at /password-reset/ (530, b'5.5.1 Authentication Required. Learn more at\n5.5.1 https://support.google.com/mail/?p=WantAuthError n10sm7332209pfj.14 - gsmtp', 'webmaster@localhost') EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = os.environ.get('EMAIL_USER') EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS') I am already turn on lower access app from gmail. I managed to receive the email in my gmail account by test locally. But when I tested it in website, I get this error. -
Django 2.1/Python 3.7 SSL Error Local Host
I'm attempting to do an esearch of the BioPython database using Django 2.1 and Python 3.7 but I seem to be getting an odd SSL Error I never got with earlier versions of Python/Django (i'm on a Mac) I've install certifi but nothing seems to have happened. def results(request): disease = request.GET.get('disease_name') year_beginning = request.GET.get('year_beginning') year_ending = request.GET.get('year_ending') Entrez.email = "test@gmail.com" handle = Entrez.esearch( db="pubmed", sort="relevance", term=disease, mindate=year_beginning, maxdate=year_ending, retmode="xml", ) results = Entrez.read(handle, validate="False") handle.close() print(results) context = { 'results': results, } return render(request, 'lm_test/results.html', context) This should return results similar to https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmode=xml&retmax=20&sort=relevance&term=fever but I just seem to be constantly getting an ssl error in my local host? -
django displaying posts and comments
this is models.py class Post(models.Model): author = models.ForeignKey('auth.User', on_delete=models.CASCADE) title = models.CharField(max_length=100) content = models.TextField() date = models.DateTimeField(default=timezone.now) def write(self): self.date = timezone.now() self.save() def __str__(self): return self.title class Comment(models.Model): post = models.ForeignKey('humorge.post', on_delete=models.CASCADE, related_name='comments') author = models.CharField(max_length=100) content = models.TextField() date = models.DateTimeField(default=timezone.now) def add_coment(self): self.date = timezone.now() self.save() def __str__(self): return self.content and this is views.py def mainpage(request): return render(request, 'index.html') def post(request): datas = Post.objects.order_by('-date') comments = Comment.objects.all() return render(request, 'post.html', {'datas': datas, 'comments': comments}) and this is template {% extends 'layout.html' %} {% block main %} <div class="container"> {% for data in datas %} <div class="row"> <div class="col s12 m7"> <div class="card"> <div class="card-image"> <img src="#"> <span class="card-title">{{ data.title }}</span> </div> <div class="card-content"> <p>{{ data.content }}</p> </div> <div class="card-action"> <p>{{ data.date }}</p> </div> <div class="card-action"> {% for comment in comments %} {% if comment.post == data.title %} {{ comment.date }}<br> <strong>{{ comment.author }}</strong> <p>{{ comment.content }}</p> {% endif %} {% empty %} <p>There is no comments</p> {% endfor %} </div> </div> </div> </div> {% empty %} <p>there is no posts</p> {% endfor %} </div> {% endblock %} I want to display posts and comments when I try to have two posts and each post has one … -
How to get value in template from model through another one?
I have two models connected by one-to-many relation. How can I get value from one field of one model through another? I need to get value "low" from Image model from the Album model. In my Image model "low" is a path to a low-res copy of image and "path_to_image" is the path to full-size one. I use Django 2.1, build-in sqlite db. models.py: from django.db import models from django.utils.timezone import now class Album(models.Model): title = models.CharField(max_length=120) def __str__(self): return self.title class Image(models.Model): path_to_image = models.CharField(max_length=120) low = models.CharField(max_length=120) pub_date = models.DateField(default=now) album = models.ForeignKey(Album, on_delete=models.CASCADE) def __str__(self): return self.path_to_image views.py: def albums(request): albums_list = Album.objects.all() paginator = Paginator(albums_list, 20) page = request.GET.get('page') albums = paginator.get_page(page) random_idx = random.randint(0, Image.objects.count() - 1) image = Image.objects.all()[random_idx] context = { 'albums': albums, 'image': image, } return render(request, 'gallery/albums.html', context) albums.html: <div class="item2 my-gallery responsive" itemscope itemtype="http://schema.org/ImageGallery"> {% for album in albums %} <div class="gallery"> <a href="/albums/{{ album.id }}"> <img src="{{album.image_set.model.low}}" width="300" height="225"> </a> <div class="desc">{{album}}</div> </div> {% endfor %} </div> I want to get value from Image model im that tag. So, is it possible without refactoring all code entirely? (Also, in the views.py I tried to get random image from album … -
Django - Textarea Breaks From
I have a form in Django which includes a text area. When I submit the form it is sending the request to the wrong URL. I have found that the same form without the textarea works correctly, but once the text area is included then it tries to send it to the root. Please see the console output below, the top one is the request when the form includes the textarea: [09/Feb/2019 07:28:36] "GET / HTTP/1.1" 404 3409 [09/Feb/2019 07:29:46] "POST /user/profile/ HTTP/1.1" 302 0 Not Found: / [09/Feb/2019 07:29:46] "GET / HTTP/1.1" 404 3409 [09/Feb/2019 07:29:53] "POST /user/profile/ HTTP/1.1" 200 19883 [09/Feb/2019 07:29:54] "GET /static/user/css/bootstrap.min.css.map HTTP/1.1" 304 0 When it has the text area I get "Not Found: /". Please see the HTML code below for the two forms: <div class="row" style="padding-left:20px;"> <form method="post" action=""> {% csrf_token %} <div class='form-group row'> <p>Register as driver:</p> </div> <div class='form-group row'> <label>Make: </label>{{ form.vehicle_make }} </div> <div class='form-group row'> <label>Model: </label>{{ form.vehicle_model }} </div> <div class='form-group row'> <label>Pasengers: </label>{{ form.numberofpassengers }} </div> <div class='form-group row'> <label>Vehicle Description: </label>{{ form.vehicle_description }} </div> <div class='form-group row'> <input type='submit' name="submit" class='btn btn-primary' value="Submit"> </div> </form> </div> <form method="post" action=""> {% csrf_token %} <div class='form-group row'> … -
Django model instance deleted if exception raises
I am using Django==1.11.3, If exception is raised while accessing instance method it deletes object. Below is an example class SomeModel(models.Model): key = models.CharField(max_length=250) response = models.TextField(blank=True, null=True) @classmethod def add_api_response(cls, key, response): obj = cls.objects.create( key=key,response=response ) response_data = SomeModel.add_api_response( key=some_key, response=some_response ) # ^ above codes creates a object with id `x` response_data.get() # OR response_data.any_unknown() # ^ above codes deletes it I am new to Django please guide if its expected behavior i.e it deletes the model on raising exception or i should be missing any exception hook? Thanks in advance for your help -
How to receive post data from external redirects while maintaining login state in a mobile app(ionic)
I want to build a mobile app that can be used for website as well. So going with ionic as both website and mobile app can be built with same code. I got confusion regarding integration with third party applications. One such third party service works like this: Our site redirects(using post request) to third party and people enter things like credit card in that site and it will redirect to our site with post request/data. I tried using in app browser in ionic which successfully sent post request to third party site. But when it redirected back, if it redirects with get parameters, I would have captured them. But it is redirecting with post data and seems like ionic cannot capture post data. So, thinking of capturing using server urls. But when I do with server urls, how do I maintain login state? Because people will be logged into the app, not server. So, this way, people might be asked to login to the server again? So, what is the correct way to go here? Also, should I use token authentication or session authentication to make this work? Thanks. -
How to programmatically get the information from this request body in Django
I am trying to get the filename from the request body. I am able to print the request body... However, I am not able to get any information from it. programmatically Also, apparently its not in json format and I cannot use the solution from these links -- Trying to parse `request.body` from POST in Django Below is a copy of the request body from request.read b'------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="fileItem"; filename="IMG_6427.ico"\r\nContent-Type: image/vnd.microsoft.icon\r\n\r\n\x00\x00\x01\x00\x01\x00\x18 \x00\x00\x01\x00 \x00\xa8\x0c\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x18\x00\x00\x00@\x00\x00\x00\x01\x00 \x00\x00\x00\x00\x00\x00\x0c\x00\x00\x12\x0b\x00\x00\x12\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x006<F\xff\x89\x84\x84\xffD76\xff\x85\x87\x85\xffKac\xff9NR\xff)67\xff\x19$+\xff&0>\xff\x10\x14\x16\xff\x08\r\r\xff\x04\t\t\xff\x0c\x10\x12\xff\x12\x1d\x1e\xff\x0c\x18\x17\xff\x08\r\r\xff\x05\x06\x07\xff\x06\x01\x01\xff\x1c)4\xff?b\x81\xffC_{\xffEUi\xffN^q\xffQf~\xffo/1\xffS\x18\x19\xffNFT\xff~\x81\x8c\xffi\x86\x91\xffC^i\xffUnu\xff?NT\xff+-4\xff055\xffG\x1f\x1d\xff3\x1d\x1e\xff\x1d&,\xff\x1f\'1\xff\x07\x0f\x0c\xff\x0c\x15\x15\xff\x08\t\n\xff\x08\x06\x08\xff!0=\xff\x1a",\xff \'3\xff/:K\xffuH>\xffpMM\xff\xa3*$\xffk"!\xffS$*\xff^[m\xffh\x87\xa1\xffLh\x83\xffr\x99\xb6\xff\x9d\xcf\xe8\xffz\x9e\xab\xffBEJ\xffo07\xff[06\xff8=I\xff=KZ\xff0GT\xff\x13\x19\x1b\xff\x04\x01\x00\xff\x18$+\xffMr\x91\xffAWp\xff,/;\xff\x0b\x0c\r\xff\'\x1e\x1e\xff==H\xfft5<\xffO06\xff`\x1c\x18\xff=\x1e \xff))6\xffRp\x8c\xffh}\x99\xffty\x92\xffk\x81\x9a\xffTRe\xff\x8433\xffdKR\xffKSc\xffE\\s\xffE^u\xff\x13\x15\x1a\xff\x13\x13\x16\xff5HZ\xffNo\x8d\xffM_y\xff?FX\xff\x0f\x14\x14\xff\x12\x19\x1f\xff!&2\xff_N`\xff\x8d13\xffz$!\xff9\x13\x14\xffuw~\xff\x81\x95\xab\xffay\x94\xffcz\x9d\xff^e}\xffcOb\xffe(\'\xffgP[\xffl}\x94\xffEYo\xff\x15\x16!\xff\x06\x03\x02\xff\')1\xff&0>\xff",:\xff5;K\xff03>\xff45@\xffBL`\xff9@R\xff?Ob\xffj).\xff},,\xffJ%*\xffnlu\xffiho\xffcjv\xff@DS\xff8-4\xffV5<\xffK((\xffR9D\xffx\x88\x98\xff\x1a",\xff\x03\x00\x02\xff\x06\x04\x06\xff$$-\xff@Vl\xff-;J\xff#\x1f\'\xff\'+3\xff(2=\xff",7\xff\'*5\xffPju\xffKOW\xff=%,\xffQ(,\xffB\x1d"\xff3\x10\x10\xff:\x1d\x1c\xff?"\x1e\xffD#\x1d\xffD\x1e\x19\xffI\x1f\x1d\xffO6=\xffLLU\xff\x07\t\x0c\xff\x07\x03\x05\xff\x0b\x06\x08\xff\x05\x06\x07\xff(\x18\x1c\xffM6A\xff49E\xff9:E\xff;1:\xff9+4\xff=*0\xffGQ`\xffER_\xff`6>\xffX(*\xff_%\'\xffV\x1f\x1f\xff0\x15\x14\xff9\x1e\x1d\xffH!\x1c\xffJ#"\xff6\x17\x17\xff)\x1a\x1b\xff\x1f\x1e%\xff\x05\x05\x0e\xff\x0c\x05\x05\xff\x02\x06\x08\xffE\x16\x15\xff\x87!\x18\xff?\x19\x1a\xffH#0\xffn1<\xff\\\'.\xffZ38\xffham\xffA`x\xffZL[\xffn4<\xffO\'0\xff8!&\xffX&+\xff[,1\xff5\x1e#\xff+\x14\x15\xff8 %\xff/\x19\x1b\xff#\x14\x14\xff\x1a\x14"\xff\x0c\x10%\xff\x04\x03\x02\xff\x1c\r\x0e\xff\x84\'\'\xffp%&\xff9*.\xff\x82;:\xffp#*\xffzAG\xffH?L\xff2:J\xffC]r\xffQHU\xffT\'-\xff&\x1c%\xff"\x1e&\xff$\x1b"\xffV3:\xffq8>\xffV&(\xffN!!\xffK%(\xffG+.\xffL+6\xff&\'>\xff\x11\x05\x06\xff"\x0c\n\xffu..\xffj\'\'\xff\x90JF\xff\xb0WP\xffsHT\xff\x8e\x9e\xae\xffAGQ\xff3.2\xffPax\xff0=H\xff\x1f!&\xff&#)\xff\'\x1e%\xff(\x1f&\xff#\x1c#\xff,\x1b!\xff@$\'\xffL#$\xff=%*\xffg \x1f\xff^"%\xffM\x1b"\xff\x83\x1d\x1b\xff\x1d\x0f\x10\xff<\x0f\x0e\xffl!\x1c\xffq+\'\xffN25\xffBOZ\xffGcq\xff=<B\xff758\xffL`t\xffK[n\xff7AL\xff&%+\xff$$\'\xff&\x1f&\xff+\x1d%\xff\'\x1e%\xff+\x1c!\xff,\x1d!\xff7*/\xffW!#\xff~\x1f\x19\xff\x8b\x18\x11\xffm"#\xffi\x1d\x1a\xff2\x1a\x1f\xffg,-\xff>6:\xff9;B\xff:59\xff97:\xff87=\xff:7=\xffOau\xffPaq\xffQbr\xffBLW\xff/(/\xff""%\xff\'#%\xff&\x1d$\xff*\x1c$\xff%\x1e%\xff=!$\xffO),\xffW%(\xff\\%%\xffQ\x1c\x1c\xff5\x17\x19\xff;\x1f)\xff8\'/\xff>@E\xff?<B\xff;=B\xff:<A\xff;:@\xff;:@\xffPcu\xffQbr\xffRcq\xffNer\xfftLT\xffU37\xff##&\xff#\x1f!\xff%\x1e%\xff%\x1c#\xff\'\x1c!\xff^(*\xff{36\xffI#&\xff$\x12\x16\xff!\x11\x15\xff%\x13\x17\xff=8>\xff@BI\xff>?F\xff=>E\xff<=D\xff<=D\xff;<C\xffRew\xffSes\xffTes\xffMfs\xffyWb\xff\xabW_\xffxIO\xff0(,\xff\x1f\x1e$\xff\'$*\xff+ %\xff.\x1e"\xff\x7f$ \xffE\x15\x17\xff/\x13\x16\xff/ $\xff<>E\xffFLT\xffDHP\xffBFN\xffBDL\xff@BJ\xff>@G\xff>?F\xffThw\xffVhv\xffVgt\xffVmz\xfflXb\xff\xac>=\xff\x96?@\xffc)+\xff/!"\xff\x1c!\'\xff"#*\xff+&,\xffo23\xffP !\xffM>B\xffR[a\xffT]d\xffMS[\xffJPX\xffIOY\xffGMW\xffEKU\xffCIS\xffBFN\xffXjx\xffXjx\xffZkx\xff[o}\xffeaj\xff\x92($\xffj##\xffV #\xff\x82/-\xffv1+\xff+&*\xff# &\xff504\xffXag\xffdsy\xff`kr\xffYdk\xffU^e\xffQZa\xffNV`\xffMU_\xffNT^\xffLR\\\xffINZ\xff[m{\xff[m{\xff\\mz\xffat\x80\xffY\\h\xffW&+\xffO),\xffI*0\xff\xac3-\xff\xc3:-\xff{51\xffI57\xffotz\xffhy\x7f\xffdpw\xffcov\xff`ls\xff\\gn\xffZcj\xffW`g\xffU]g\xffS[e\xffRXb\xffOU_\xff[o}\xff^p~\xff_p}\xffcv\x82\xffcis\xffX5<\xffL.6\xffV&(\xff\x8e\'!\xff\x9a,#\xffa \x1b\xff^[a\xffm\x80\x88\xffiu|\xffgv|\xffgsz\xffdpy\xffbnu\xff`kr\xff^gn\xffZcj\xffW`g\xffU]g\xffRZd\xff`r\x80\xff`r\x80\xffct\x81\xffdw\x83\xffpz\x85\xff\xa5\\b\xffx7<\xffI\'+\xff[%\'\xff[\'$\xffaRV\xffiz\x80\xffl{\x81\xffl{\x81\xffl{\x81\xfflx\x7f\xffiu~\xffhr|\xffeoy\xffbmt\xff^ip\xff\\el\xffX`j\xffV^h\xffau\x83\xffdv\x84\xfffy\x85\xffh{\x87\xffqy\x83\xff\xac]d\xff\xb897\xff\x85 \x1a\xffX()\xff\x81KM\xffu\x83\x8c\xffl}\x83\xffn}\x83\xffm|\x82\xffl{\x81\xffmy\x80\xfflx\x7f\xfflw~\xffjt~\xffgq{\xffdov\xff`kr\xff^gn\xffZbl\xffd{\x88\xffhz\x88\xffj}\x89\xffl\x7f\x8b\xffrz\x84\xff\xb6U\\\xff\xc56$\xff\xe9#\t\xff\xc45)\xff{ry\xffm\x80\x88\xffp|\x83\xffp\x7f\x85\xffr~\x85\xffn}\x83\xffo{\x82\xffnz\x81\xffmy\x80\xffmy\x80\xfflw~\xffis}\xffeoy\xffdlv\xff`hr\xffi}\x8b\xffl~\x8c\xffm\x7f\x8d\xffn\x83\x8f\xff|z\x83\xff\xc2[f\xff\xcf(\x1c\xff\xe5$\x13\xff\xa6[\\\xffj\x82\x8b\xffr~\x87\xffq\x80\x86\xfft\x80\x87\xfft\x80\x87\xffq\x80\x86\xffp\x7f\x85\xffo~\x84\xffp|\x85\xffp|\x83\xffo{\x82\xffmy\x80\xffjt~\xffgq{\xffdnx\xffk\x82\x8f\xffn\x82\x90\xffq\x83\x91\xffn\x87\x94\xff\x96~\x85\xff\xc9A>\xff\xd1\x1a\t\xff\xd2H?\xff\x86\x83\x8f\xffp~\x87\xfft\x80\x89\xffr\x81\x87\xffs\x82\x88\xfft\x83\x89\xffs\x82\x88\xffs\x82\x88\xffr\x81\x87\xffq\x7f\x88\xffr~\x87\xffr~\x87\xffq}\x86\xffnz\x83\xfflv\x80\xffis~\xffm\x85\x94\xffp\x87\x94\xffu\x87\x95\xffq\x8b\x99\xff\x9f{\x84\xff\xc40\'\xff\xdb2 \xff\xb3rw\xfft\x84\x8e\xffu\x7f\x89\xffs\x81\x8a\xffu\x81\x8a\xfft\x83\x89\xffw\x83\x8a\xffu\x84\x8a\xffw\x83\x8a\xffu\x84\x8a\xfft\x82\x8b\xffs\x81\x8a\xffs\x7f\x88\xffq\x7f\x88\xffp|\x85\xffmy\x82\xffkw\x80\xffn\x88\x96\xffr\x88\x97\xffx\x89\x97\xffr\x8d\x9e\xff\xb1gh\xff\xd0,\x1d\xff\xddNJ\xff\x84}\x87\xfft\x81\x8c\xffv\x82\x8b\xfft\x82\x8b\xffu\x83\x8c\xffv\x84\x8d\xffw\x86\x8c\xffy\x85\x8c\xffw\x86\x8c\xffw\x86\x8c\xffw\x85\x8e\xffv\x84\x8d\xfft\x82\x8b\xffs\x81\x8a\xffq\x7f\x88\xffo}\x86\xffnz\x83\xffn\x88\x96\xffr\x89\x96\xffw\x89\x97\xffy\x8d\x9c\xff\xbcGE\xff\xe4(\x19\xff\xc6z\x7f\xfft\x85\x92\xffx\x82\x8d\xffw\x82\x8d\xffu\x83\x8c\xffv\x84\x8d\xffw\x85\x8e\xffx\x87\x8d\xffx\x87\x8d\xffy\x88\x8e\xffy\x87\x90\xffy\x87\x90\xffx\x86\x8f\xffw\x85\x8e\xfft\x84\x8d\xffr\x82\x8b\xffp\x80\x89\xffo\x7f\x88\xffn\x86\x95\xffr\x86\x94\xffs\x89\x98\xff\x8e\x82\x8b\xff\xd4&\x13\xff\xeaTI\xff\xa5\x8e\x99\xfft\x84\x8e\xffz\x84\x8f\xffv\x83\x8e\xffv\x84\x8d\xffw\x85\x8e\xffz\x86\x8f\xff{\x87\x90\xffy\x88\x8e\xffz\x89\x8f\xffz\x89\x8f\xffz\x88\x91\xffz\x88\x91\xffy\x88\x8e\xffv\x87\x8d\xffu\x85\x8e\xfft\x84\x8d\xffr\x82\x8b\xffl\x84\x93\xffr\x84\x92\xffn\x88\x95\xff\x95\x81\x8a\xff\xf6QE\xff\xdfwu\xff\x81\x8b\x96\xffx\x85\x90\xffx\x85\x90\xffw\x84\x8f\xffw\x85\x8e\xffw\x85\x8e\xffz\x86\x8f\xff{\x87\x90\xffy\x87\x90\xffz\x88\x91\xffz\x89\x8f\xffz\x88\x91\xffy\x89\x92\xff{\x89\x92\xffx\x88\x91\xffu\x88\x90\xfft\x87\x8f\xfft\x84\x8d\xffl\x82\x91\xffq\x83\x91\xffr\x83\x90\xff\xcawu\xff\xfbXE\xff\xbejh\xffs\x8a\x97\xffz\x85\x90\xffw\x84\x8f\xfft\x84\x8e\xfft\x84\x8e\xfft\x84\x8d\xffx\x86\x8f\xffx\x86\x8f\xffx\x86\x8f\xffy\x87\x90\xffz\x88\x91\xffy\x89\x92\xffy\x89\x92\xffy\x89\x92\xffz\x8a\x93\xffw\x8a\x92\xffv\x89\x91\xfft\x87\x8f\xffk\x7f\x8d\xffm\x81\x8f\xffv\x80\x8e\xff\xbc61\xff\xe36\x19\xff\x97cf\xfft\x8b\x98\xffy\x84\x8f\xffu\x85\x8f\xffu\x85\x8f\xffr\x84\x8e\xffs\x86\x8e\xffu\x85\x8e\xffv\x86\x8f\xffw\x87\x90\xffw\x87\x90\xffx\x88\x91\xffy\x89\x92\xffz\x8a\x93\xffx\x8b\x93\xffy\x8c\x94\xffx\x8c\x94\xffw\x8b\x93\xffv\x8a\x92\xffk\x7f\x8d\xffl~\x8c\xffl\x82\x91\xff\x83_h\xff\x86^f\xffu\x87\x95\xfft\x83\x90\xffu\x85\x8f\xffs\x85\x8f\xffr\x84\x8e\xffr\x84\x8e\xffs\x85\x8f\xffu\x85\x8e\xfft\x87\x8f\xffw\x87\x90\xffx\x88\x91\xffy\x89\x92\xffz\x8a\x93\xffx\x8b\x93\xffy\x8c\x94\xffy\x8d\x95\xffz\x8e\x96\xffz\x8e\x96\xffw\x8d\x95\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="name"\r\n\r\nIMG_6427.ico\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="lastModified"\r\n\r\n1546156330437\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="lastModifiedDate"\r\n\r\nSun Dec 30 2018 15:52:10 GMT+0800 (Hong Kong Standard Time)\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="webkitRelativePath"\r\n\r\n\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="size"\r\n\r\n3262\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="type"\r\n\r\nimage/vnd.microsoft.icon\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="slice"\r\n\r\nfunction slice() { [native code] }\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="name"\r\n\r\nIMG_6427.ico\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="raw_filename"\r\n\r\nIMG_6427.ico\r\n------WebKitFormBoundary37UfK4cafPJyv12M\r\nContent-Disposition: form-data; name="filetype"\r\n\r\nimage/vnd.microsoft.icon\r\n------WebKitFormBoundary37UfK4cafPJyv12M--\r\n' def post(self, request, *args, **kwargs): print("request.read",request.read()) body_unicode = request.body.decode('utf-8') body_data = json.loads(body_unicode) -
Django/Vue braces added to request method after logout
I have a basic user management project that I'm using off of which to scaffold other projects. It is a Vue CLI 3 front end and Django/Django REST Framework/Django REST Auth back end. The project I'm posting here uses sqllite but it can relatively easily be converted to another db. Here is the link to the full repo for anyone who is willing to download to try to replicate my issue: https://github.com/JVP3122/user-project I'm having a very strange problem in that when I log out of the site and then try to log back in directly from the same page it seems that axios is adding the payload to the beginning of the request method. For example, in the images found in the post I put up in Imgur (https://imgur.com/a/bEsx662) the user name is simply "test" with the password "password", and when I try to log back in after logging out the subsequent login attempt is no longer a POST route, but instead a {}POST route. If I try again, the route becomes a {"USERNAME":"TEST","PASSWORD":"PASSWORD"}POST method. I've tried looking at the config in the axios request interceptor, looking at the dispatch method in the rest_framework source code, and I can't figure … -
Prevent Jinja code from wrapping into one single line in CKEditor 4?
I'm using CKEditor 4.x for the purpose of jinja html template code. Therefore, I tried to configure it to support jinja language in source view of CKEditor. With this concern, I would like editor not to wrap my jinja code as a single line. For example, if I write below in source view of editor: {% if name=='hello' %} {{ 'hello' }} {%else%} {{ 'what is your name?' }} {% endif %} Then I switch wysiwg view and back to source code again, I would like it to above code as the same. However, currently it wraps above code as a single line like this: {% if name=='hello' %}{{ 'hello' }} {%else%} {{ 'what is your name?' }} {% endif %} Here is inside my current config.js file: /** * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. * For licensing, see https://ckeditor.com/legal/ckeditor-oss-license */ CKEDITOR.editorConfig = function( config ) { // Define changes to default configuration here. For example: config.removePlugins = 'easyimage, cloudservices'; config.height = 800; config.toolbarCanCollapse = true; /* skin */ config.skin = 'office2013'; config.extraPlugins = 'codemirror,placeholder,textindent,floating-tools,textselection,tableresizerowandcolumn,quicktable'; // 1. Codemirror config.codemirror = { // Define the language specific mode 'htmlmixed' for html including (css, xml, javascript), … -
Django Rest Framework - CreateAPIView ForeignKey lookup fields
I am using Django Rest Framework CreateAPIView in order to create a comment. So far everything is OK and here is my code. Models class Posts(models.Model): title = models.CharField(max_length=512, null=True) slug = models.CharField(max_length=512, null=True) class Comments(models.Model): post = models.ForeignKey(Posts, on_delete=models.CASCADE) content = models.CharField(max_length=5000, null=True) Serializer class CommentCreateSerializer(ModelSerializer): class Meta: model = Comments fields = [ 'content', 'post' ] and view class CommentCreateView(CreateAPIView): permission_classes = [IsAuthenticated] queryset = Comments.objects.all() serializer_class = CommentCreateSerializer I sent a post request to the create route with post(ID) and content and everything worked. But the problem is I wanna pass post slug instead of post ID. I am not sure how can I do that. I am familiar with lookup_fields but I am not certain how to apply them for ForeignKey match. -
how to solve this Python Setup Problem in cpanel
Please Click Here to See The Error i have bought a shared hosting & the "cpanel" have the python setup option. But whenever i try to use this option for installing django this error shows up. I have the Shell Access . How can i solve this problem using ssh? -
Autopopulated field doesn't work with forms
I have shop application, and in this app i have form that allow me to add comments under products, almost everything works fine but only when I add comments by admin panel, when I try add comment as user by form in my page, author column have value=None Like you can see on this image when I'm trying to add comment as user by form in page, then field in column Nick which should show user who added this comment show only '-' but when i add comment as admin by admin panel then everything works correctly models.py: class Comment(models.Model): STATUS_CHOICES=(('1/5','1'), ('2/5','2'), ('3/5','3'), ('4/5','4'), ('5/5','5'), ) nick=models.ForeignKey(User, editable=False, null=True, blank=True, on_delete=models.CASCADE) rate=models.CharField(max_length=3, choices=STATUS_CHOICES, default=None) content=models.TextField() product=models.ForeignKey(Product, related_name='comments', on_delete=models.CASCADE, default=None) published=models.DateTimeField(auto_now_add=True) class Meta: ordering=('published',) def __str__(self): return 'Komentarz wstawiony przez {} do produktu {}'.format(self.nick, self.product) admin.py class CommentAdmin(admin.ModelAdmin): list_display=('nick','rate','product','published') list_filter=('rate','published') search_fields=('product__name',) date_hierarchy='published' ordering=('product','rate') def save_model(self, request, obj, form, change): obj.nick = request.user super().save_model(request, obj, form, change) def product__name(self, instance): return instance.product.name admin.site.register(Comment, CommentAdmin) form.py class CommentForm(ModelForm): class Meta: model=Comment fields=['rate', 'content'] -
Table Meta 'row_attrs' are not passed to Table constructor
I'm using django_tables2 library in my project and trying to implement a table where each row would possess a data-item-name attribute. My specific table is inherited from my BaseTable class which in its turn is inherited from django_tables2.Table class. Here is the code: page_table.py import django_tables2 as tables from django.utils.html import format_html from myapp.utils.tables import BaseTable from myapp.models import MyModel class PageTable(BaseTable): item_number = tables.Column(accessor='pk') # This method works perfectly fine as expected def render_item_name(self, record): return format_html( '<span data-item-id="{0}">{1}</span>'.format( record.item_id, record.item_name ) ) class Meta: model = MyModel # When debugging this attribute is accessed only on booting up # And is ignored when I for example first visit or refresh the page row_attrs={ 'data-item-name': lambda r: r.item_name } fields = ( 'item_id', 'item_name', 'item_description', 'item_price', # etc ) base_table.py import django_tables2 as tables class BaseTable(Table): def __init__(self, *args, **kwargs): super(BaseTable, self).__init__(*args, **kwargs) Though the table is rendered without errors and nothing breaks up, there is no data-item-name attribute not on a single row in the table, although as far as I've gone through docs, it's said that declaring this property in table's metaclass is enough. Am I mistaken or is there something I missed in this? Any help … -
Cannot migrate: relation does not exist (Django 2.1)
When I try to migrate, I get this error: "django.db.utils.ProgrammingError: relation "TEST" does not exist". However, TEST is a postgresql table I no longer use. Right now, I have my models.py set to getting data from another table: class cross_currents(models.Model): ArticleID = models.IntegerField(primary_key=True) class Meta: db_table = 'cross_currents' def __str__(self): return f'{self.Title}, {self.Author}, {self.Journal}, {self.Pub_Year}, {self.Issue}' def get_absolute_url(self): return reverse('article-detail', args=[str(self.ArticleID)]) As you can see, my db_table is set to another table, not TEST (it was previously set to TEST), but migrate somehow keeps looking for TEST. Other than changing the value of db_table, what else do I need to do to tell Django that TEST is no longer used? Full traceback: https://imgur.com/a/Loz4Q89 -
Heroku Application Erros Django
I don't understand why this application error. I followed djangogirls-extension deploy tutorial. here is the output of >heroku logs --tail --app srms-demo command 2019-02-09T02:31:06.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9822ee2e-0b33-4163-9dd1-5d9897a5b7c7/activity/builds/e01929d2-7a31-45fe-97c3-90eab053a667 2019-02-09T02:47:00.587192+00:00 heroku[run.9364]: State changed from up to complete 2019-02-09T02:50:39.686144+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=srms-demo.herokuapp.com request_id=5859852f-3ae2-47c8-9f6e-3ba05f1c5bbb fwd="43.245.123.100" dyno= connect= service= status=503 bytes= protocol=https 2019-02-09T03:10:39.561398+00:00 heroku[run.2791]: Process exited with status 0 2019-02-09T03:11:20.141798+00:00 heroku[run.6801]: State changed from up to complete 2019-02-09T03:15:30.610720+00:00 heroku[web.1]: State changed from crashed to starting then is visited error link and found this -----> Python app detected ! Requested runtime (python-3.7) is not available for this stack (heroku-18). ! Aborting. More info: https://devcenter.heroku.com/articles/python-support ! Push rejected, failed to compile Python app. ! Push failed -
configure toolbar to paste plain text django-ckeditor
Can anyone tell me how to paste plain text in ckeditor using django's admin? Everytime that I try to paste something from my clipboard it pops that message. Press Ctrl+V to paste. Your browser doesn‘t support pasting with the toolbar button or context menu option.