django

how can I convert an incorrectly-saved bytes object back to bytes? (python/django)

心已入冬 提交于 2021-02-11 15:48:57
问题 I've downloaded some web pages with requests and saved the content in a postgres database [in a text field] using Django's ORM. For some sudocode of what's going on, here ya go: art = Article() page = requests.get("http://example.com") art.raw_html = page.content art.save() I verified that page.content is a bytes object, and I guess I assumed that this object would automatically be decoded upon saving, but it doesn't seem to be... it has been converted to some weird string representation of a

Error: You are trying to add a non-nullable field 'password' to account without a default during Django migrations

牧云@^-^@ 提交于 2021-02-11 15:40:52
问题 I am tying to build a custom user model in a Django app, instead of using the built-in one. models.py from django.contrib.auth.models import AbstractBaseUser from django.db import models from django.contrib.auth.models import BaseUserManager class AccountManager(BaseUserManager): def create_user(self, email, password=None, **kwargs): if not email: raise ValueError('Users must have a valid email address.') if not kwargs.get('username'): raise ValueError('Users must have a valid username.')

Passing django template variables to js datatables

て烟熏妆下的殇ゞ 提交于 2021-02-11 15:40:41
问题 Hi I would like to create table using JS datatables library. I got problem when passing value in template to js script. I created JSON object from my table which I want to display. It's passed correctly to template, when I display it everything is fine, but when trying to pass it to script nothing happend and I got empty table. Thats the way I do it: class VotesList(generic.ListView): model = Vote template_name = 'votes-list.html' def get_context_data(self, **kwargs): votes = Vote.objects.all

How to allow/ reject api permisions based on user group in django rest framework

时光毁灭记忆、已成空白 提交于 2021-02-11 15:36:14
问题 I have 2 groups of user Creator and viewer Creator can create,update, view , delete data while Viewer only can view data. I cant understand how to implement them easily.:Later on if Imay have to allow certain crud for different models. i feel if groups can have custom acess I will have full control , maybe a custom class I have separated the apis now need to check if group matches then allow action on the api. serializer.py from rest_framework import serializers from trackit_create.models

How to allow/ reject api permisions based on user group in django rest framework

徘徊边缘 提交于 2021-02-11 15:34:24
问题 I have 2 groups of user Creator and viewer Creator can create,update, view , delete data while Viewer only can view data. I cant understand how to implement them easily.:Later on if Imay have to allow certain crud for different models. i feel if groups can have custom acess I will have full control , maybe a custom class I have separated the apis now need to check if group matches then allow action on the api. serializer.py from rest_framework import serializers from trackit_create.models

How To Get Rid Of “Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)” in Pychar+Django

ε祈祈猫儿з 提交于 2021-02-11 15:30:08
问题 When I run my test suite using pycharm for a django app in my local machine, at certain test I got: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) If I run that test in isolation using pycharm, it succeeds, which means there's not a problem in the app or test. If I disable that particular test, down the line I get the same error, in a different test, this one a dummy test! This seems to indicate that it's a problem with pycharm itself. The full test suite succeeds in

How To Get Rid Of “Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)” in Pychar+Django

随声附和 提交于 2021-02-11 15:29:54
问题 When I run my test suite using pycharm for a django app in my local machine, at certain test I got: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) If I run that test in isolation using pycharm, it succeeds, which means there's not a problem in the app or test. If I disable that particular test, down the line I get the same error, in a different test, this one a dummy test! This seems to indicate that it's a problem with pycharm itself. The full test suite succeeds in

How to replace #text with a link? [duplicate]

安稳与你 提交于 2021-02-11 15:26:39
问题 This question already has answers here : Change #hash tag to link on page load (2 answers) How do I use javascript to replace hash tags with links from a jquery data-attribute (2 answers) Javascript/jQuery - parse hashtags in a string using regex, except for anchors in URLs (3 answers) Closed last year . I have created a post in Django. When a user types text and hits submit it shows in the page. Now I want to turn any hashtags in the text in to links. For example if a user types #sometext it

How to replace #text with a link? [duplicate]

流过昼夜 提交于 2021-02-11 15:26:25
问题 This question already has answers here : Change #hash tag to link on page load (2 answers) How do I use javascript to replace hash tags with links from a jquery data-attribute (2 answers) Javascript/jQuery - parse hashtags in a string using regex, except for anchors in URLs (3 answers) Closed last year . I have created a post in Django. When a user types text and hits submit it shows in the page. Now I want to turn any hashtags in the text in to links. For example if a user types #sometext it

using django template lanuage to realize greater and less

时间秒杀一切 提交于 2021-02-11 15:15:53
问题 papis i have a dict here dict = {1: [1,2,3,4,5,6,7,8,9], 2: [2,4,5,6,7,8,9,0], 3: [5,2,4,6,12,3,7,6]} i want show it on my page so i using template as follows: {%for item in dict.items%} <tr> <td>{{item.0}}</td> {%for v in item.1%} here ,i dont know how to handle if last column and v >5 <td color = 'red'>{{v}}</td> else <td>{{v}}</td> {%endfor%} </tr> {%endfor%} as you see,i want the last column turn red text if its value is greater than 5 how can i realize this ,i google and found nothing