Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Nested relationships REST serializers
models.py class Item(models.Model): name=models.CharField(max_length=500) short_description=models.CharField(max_length=500) restaurant=models.ForeignKey(Restaurant,on_delete=models.CASCADE) def __str__(self): return str(self.name) class ItemVariation(models.Model): restaurant=models.ForeignKey(Restaurant,on_delete=models.CASCADE) item=models.ForeignKey(Item,on_delete=models.CASCADE) price=models.IntegerField(blank=True,null=True,default=0) item_code=models.CharField(max_length=500) keyword= models.ManyToManyField(Keyword) image=models.ImageField(upload_to='dishes/', blank=True, null=True) def __str__(self): return str(self.id) serializers.py class ItemsSerializer(serializers.ModelSerializer): class Meta: model = Item fields =('name','short_description') class ItemVariationSerializer(serializers.ModelSerializer): items = ItemsSerializer(many=True, read_only=True) class Meta: model = ItemVariation fields ='__all__' response: { "id": 7, "price": 0, "item_code": "test", "image": "/media/dishes/download_3_kcE78IS.jpeg", "restaurant": 1, "item": 7, "keyword": [ 3 ] } my response is like this but i'm not getting related field item in my response. can anyone suggest where i'm wrong. this code is returning ItemVariation object fields but i also need related item. -
Unable to send whole object to another Django views
As I have seached through StackOverflow and already tried all those answer still not work for me. My project is to use telnetlib to connect device via Django webapp. I stuck in passing telnet object between views with request.session. Class A(TemplateView): def post(self, request, *args, **kwargs) obj = telnetlib.Telnet(host,timeout) request.session['obj'] = obj return render(request,'next.html',{}) Class B(TemplateView): def post(self, request, *args, **kwargs) obj2 = request.session.get('obj') ... ... Then I got error: Object of type 'TelnetThing' is not JSON serializable And already tried to serialize it to json (which I kind of no idea what it is) and still not working 'TelnetThing' object has no attribute '_meta' Anyone knows how to fix this or passing whole object this way is practical? -
List Field serializer giving 'ManyRelatedManager' object is not iterable error with M2M field
My models.py looks like this: class IP(models.Model): name = models.CharField(max_length=30, unique=True) address = models.CharField(max_length=50, unique=True) class IPGroup(models.Model): name = models.CharField(max_length=50, unique=True) ips = models.ManyToManyField('IP', through='IPGroupToIP') class IPGroupToIP(BaseModel): ip_group = models.ForeignKey('IPGroup', on_delete=models.CASCADE) ip = models.ForeignKey('IP', on_delete=models.CASCADE) Now, in order to create an IPGroup, I have the following serializer: class IPGroupCreateSerializer(serializers.ModelSerializer): ips = serializers.ListField() class Meta: model = IPGroup fields = ['name', 'ips'] @transaction.atomic() def create(self, validated_data): ips_data = validated_data.pop('ips', None) ip_group = IPGroup.objects.create(name=validated_data['name']) if ips_data: for ip in ips_data: ip_obj, created = IP.objects.get_or_create(name=ip['name'], address=ip['address']) IPGroupToIP.objects.create(ip_group_id=ip_group.id, ip_id=ip_obj.id) return ip_group My views are a simple class based view as follows: class IPGroupCreateView(generics.CreateAPIView): queryset = IPGroup.objects.get_queryset() serializer_class = IPGroupCreateSerializer My JSON payload looks like this: { "ips": [{"name":"example.com", "address":"10.1.1.9"}], "name": "ipgroup1" } This how ever gives me an error stating: TypeError at /api/v1/ip-group/ 'ManyRelatedManager' object is not iterable The strange thing is that when i check the DB, the IPGroup is created along with the M2M ips. So, the code is working as expected but the view is somehow returning a 500 server error instead of a 201 created. What am i doing wrong ? -
How to have a multiple parameters on a request function in python
How can we have multiple paramets in a request in python like for example from my code it has url and auth i wanted to add a header but it results to error unexpected keyword argument. I wanted to add a header my header has the access key. Code r = requests.post('http://139.89.156.42:5033/api/1.0/session', auth=HTTPBasicAuth('fff', '123456')) for example i wanted to add a header -
Converting UUIDField to CharField
This is currently what I have in my models.py: class Campaign(models.Model): campaign_id = UUIDField(auto=True) name = models.CharField("Campaign Name", max_length=255) class CampaignResponse(models.Model): campaign = models.ForeignKey(Campaign) user = models.EmailField("Email", max_length=200) response = models.TextField() Recently I was thinking of changing the campaign_id in the Campaign model from UUIDField to CharField instead, but when I tried to do so, I noticed the data for campaign_id is being altered (e.g. the data was "7182c679f72844ca83c9648a120bb066" when UUIDField is being used, but it now becomes "7182c679-f728-44ca-83c9-648a120bb066" after converting it to CharField). Is there some steps I have to follow where I can convert that UUIDField to CharField without changing the data and ensure the relationship between Campaign and CampaignResponse is not broken? -
Any Solution to SQLDriverConnect Error in Django Occurred Below using pyodbc
I am using "django-pyodbc-azure" 3rd party library for making connection and django1.11 and python version 3.5.2 * Error in `/home/ubuntu/GET-Services_mssql/env_mssql/bin/python': double free or corruption (!prev): 0x00007f7f08078a90 * ======= Backtrace: ========= / lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f7f2a7a17e5] /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f7f2a7aa37a] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f7f2a7ae53c] /usr/lib/x86_64-linux-gnu/libodbc.so.2(SQLDriverConnectW+0x9a0)[0x7f7f24055100] /home/ubuntu/GET-Services_mssql/env_mssql/lib/python3.5/site-packages/pyodbc.cpython-35m-x86_64-linux-gnu.so(_Z14Connection_NewP7_objectbblbS0_R6Object+0x2c3)[0x7f7f242a52a3] /home/ubuntu/GET-Services_mssql/env_mssql/lib/python3.5/site-packages/pyodbc.cpython-35m-x86_64-linux-gnu.so(+0x111de)[0x7f7f242a21de] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyCFunction_Call+0x77)[0x4e9ba7] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x59f5)[0x53c6d5] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4b04)[0x53b7e4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4b04)[0x53b7e4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4b04)[0x53b7e4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x540199] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x50b2)[0x53bd92] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4b04)[0x53b7e4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x5434af] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyCFunction_Call+0x4f)[0x4e9b7f] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x614)[0x5372f4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalCodeEx+0x13b)[0x540f9b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ebd23] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4fb9ce] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_CallFunctionObjArgs+0x128)[0x5c1988] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x20bc)[0x538d9c] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4b04)[0x53b7e4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalCodeEx+0x13b)[0x540f9b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ebd98] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_CallFunctionObjArgs+0x128)[0x5c1988] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(_PyObject_GenericGetAttrWithDict+0x1bd)[0x593b9d] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x44d)[0x53712d] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x540199] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x50b2)[0x53bd92] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x540199] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x50b2)[0x53bd92] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ed3f5] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x5b7994] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x5b7fbc] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x57f03c] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4ec6)[0x53bba6] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4b04)[0x53b7e4] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalCodeEx+0x13b)[0x540f9b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ebd23] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4fb9ce] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x584716] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x5761aa] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x54320c] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x4ce6)[0x53b9c6] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalCodeEx+0x13b)[0x540f9b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ebe37] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x252b)[0x53920b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x5406df] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x54f0)[0x53c1d0] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalCodeEx+0x13b)[0x540f9b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ebe37] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyObject_Call+0x47)[0x5c1797] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalFrameEx+0x252b)[0x53920b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python(PyEval_EvalCodeEx+0x13b)[0x540f9b] /home/ubuntu/GET-Services_mssql/env_mssql/bin/python[0x4ebe37] -
update choices option of a field instance, not of the entire field
I have a model field with choices: class MyModel(models.Model): myfield = models.CharField(max_length=1000, choices=(('a','a'),('b','b')) I know that I can access in forms this specific field and override its choices option like that: self.instance._meta.get_field(field_name).choices = (('c','c'),('d','d')) but that will change the choices for the entire model, not for an individual instance. What is the correct way to do it for one specific instance only or it is not possible? -
Django filter by date
I have Class Profile(models.Model) turn_off_date = models.DateTimeField(null= True, blank = True,auto_now = False) I need to find all profile records, that have expiration date= x days from now. How do I do this? I can think of iterating through all profiles and manually comparing dates, but it seems not effective -
How to prevent employees to work from home on the company's django application
I built an ERP for a small company using Django 1.11. They are expanding now and have other companies joining them and now also use the system I built. The problem now is that some of the companies do not want their employees to be able to work from outside of the company's premises; remotely. Is there a way to achieve this on the Django application? Is there a way to tweak the Django's allowed_host setting for this purpose? Should I be checking for the location of the user connecting to the app? If so, how do I prevent the app from being fooled by those using a VPN service? -
Django rest framework 'This field is required' on relationship field
I am trying to POST to DRF api from react frontend. Here is the react part: handleSubmit(event) { event.preventDefault(); let album = {'name': this.state.selected_album, 'musician': {'name': this.state.selected_musician}}; let formData = new FormData(); formData.append('title', this.state.title); formData.append('upload', this.state.file); formData.append('youtube', this.state.youtube); formData.append('genre', this.state.selected_genre); formData.append('album', JSON.stringify(album)); fetch('/api/music/track/', { body: formData, method: 'post', headers: { 'Authorization': 'Token ' + localStorage.getItem('token'), } }).then(function (data) { return data.json(); }).then(function(data) { console.log(data); }).catch(function (err) { console.error(err); }) } Then I got this response : {"album":["This field is required."]} I checked browser's network tab, there was no empty album field. Request body: -----------------------------139814953515753314481268355557 Content-Disposition: form-data; name="title" assa -----------------------------139814953515753314481268355557 Content-Disposition: form-data; name="youtube" -----------------------------139814953515753314481268355557 Content-Disposition: form-data; name="genre" Roc -----------------------------139814953515753314481268355557 Content-Disposition: form-data; name="album" {"name":"5ugi5ht5i","musician":{"name":"sdfaf"}} -----------------------------139814953515753314481268355557-- request header: Host: localhost:3000 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0 Accept: */* Accept-Language: en-US,en;q=0.5 Referer: http://localhost:3000/upload authorization: Token **** content-type: multipart/form-data; boundary=---------------------------139814953515753314481268355557 origin: http://localhost:3000 Content-Length: 564 Cookie: csrftoken= **; tabstyle=raw-tab DNT: 1 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Serializers: class MusicianSerializer(ModelSerializer): user = serializers.HiddenField( default=serializers.CurrentUserDefault(), ) picture = serializers.ImageField(allow_null=True, write_only=True) picture_thumbnail = serializers.ImageField(read_only=True) class Meta: model = Musician fields = '__all__' class AlbumSerializer(ModelSerializer): musician = MusicianSerializer() user = serializers.HiddenField( default=serializers.CurrentUserDefault(), ) picture = serializers.ImageField(allow_null=True, write_only=True) picture_thumbnail = serializers.ImageField(read_only=True) class Meta: model = Album fields … -
How to set TimeField alone 00:00:00: in django
Here i have mentioned My model.py in this date field default i want to assign timezone as 00:00:00, so please help me to do this. Models.py class Dummy(models.Model): name = models.CharField(max_length=100) date = models.DateTimeField(null=True,auto_now_add=True) Expected output like { "id": 1, "name": "xxxx", "date": "2018-09-26T00:00:00Z" } Actual Output { "id": 1, "name": "xxxx", "date": "2018-09-26T05:52:26.626604Z" } -
django def list() with filter backend
In my application i need to customize default view,so i wrote a def_list() in django viewset. def list(self, request): id = (self.request.user.id) grp_id = account_models.User.objects.filter(pk=id).values('groups') grp = Group.objects.filter(id=grp_id) qs =services_models.ConsumerBill.objects.filter(group_id=grp).values('id','bills','minimumdue','totaldue','previousbalance','duedate','year','period') for data in qs: if (data['period']) in dct_dummy: dct_dummy[data['period']].append(data) else: dct_dummy[data['period']] = [data] return Response({'results': dct_dummy}) but i have to filter those quertyset with multiple queryparam.how can i do it?please help. -
I want to pass values are gotten in views.py to forms.py
I want to pass values are gotten in views.py to forms.py. I wrote in views.py, def app(request): if request.method == "POST": form = InputForm(data=request.POST) if form.is_valid(): name = form.cleaned_data['name'] age = form.cleaned_data['age'] in forms.py class InputForm(forms.Form): name = forms.CharField(max_length=100) age = forms.CharField(max_length=100) def logic(self): #I want to use views.py’s name&age’s value here I am new to Django ,so how should I write codes to do my ideal thing? -
Django cant pass id with url
I have read a number of other posts and the django docs and as far as i can tell i am doing this correctly but for some reason it is not working. I want to pass an items id through the url the correct way. This works <a href="/item_details/{{recent.id}}"> But this doesn't <a href="{% url 'my_app:item_details' recent.id %}"> or this <a href="{% url 'item_details' recent.id %}"> urls url(r'^item_details/(?P<item_id>\d+)/$', views.item_details, name='view_item_details'), full code {% for recent, images in recent_and_images %} <div class="item-wrapper"> <div class="item-image-wrapper"> <a href="{% url 'item_details' recent.id %}"> <img src="{{images.0}}" width="300" alt=""> </a> </div> </div> {% endfor %} error Reverse for 'item_details' with arguments '(99,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] Also my project is on Django 1.9. I checked the docs and they seem to implement this the same way however. -
Django internalization error in utf-8 encoding
I am having the following error while executing the following command in django: django-admin makemessages -l en the error is this string: Please specify the source encoding through --from-code or through a comment as specified in http://www.python.org/peps/pep-0263.html. the settings.py configurations is this: LANGUAGE_CODE = 'ru' LANGUAGES = [ ('en', 'English'), ('ru', 'Russian'), ] USE_I18N = True LOCALE_PATHS = [ os.path.join(BASE_DIR, 'locale') ] My django version is 2.1 and I am using pyCharm on Ubuntu 18.04. I did some research I found out that there is bug but it was corrected after some time. -
How to filter a Generic ListView?
I am using a CBV ListView, The problem is, the view returns a list of ALL notes on the system. What i would really prefer is for the list to only return the 'notes' that are associated with a particular CandProfile (model) The notes model is : class CandidateNote(models.Model): candidate = models.ForeignKey(CandProfile, on_delete=models.CASCADE, related_name='candidatenotes_cand') note_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, related_name='candidatenotes_user') job_note = models.TextField(max_length=3000) date_added = models.DateTimeField(auto_now_add=True) I am new to django and querying, and dont really know how to approach this in a Class based view....my initial thoughts were : Maybe i should modify the get_queryset method. Any help will be greatly appreciated. -
Python 3 TypeError: string argument expected, got 'bytes' casperjs_capture
I am getting error while executing below code with python 3 but on python 2 it is working fine template_content = <HTML data> with NamedTemporaryFile(suffix='.html') as render_file: render_file.write(template_content.encode('utf-8')) render_file.seek(0) stream = StringIO() casperjs_capture(stream, url='file://%s' % os.path.abspath(render_file.name)) Error: *** TypeError: string argument expected, got 'bytes' -
Can I use react router in django project?
I have a project that uses React in frontend and Django as backend. Also I use react router in my project and the code looks like this: <BrowserRouter> <Switch> <Route path="/" exact component={Home} /> <Route path="/teachers" exact component={Teachers} /> <Route path="/courses" exact component={Courses}/> <Route path="/about" exact component={About} /> <Route path="/posts" exact component={Posts} /> </Switch> </BrowserRouter> In django my urls file looks like this: urlpatterns = [ path('', views.index, name="index"), ] The problem is that whenever I try to navigate to the page from react router I get 404 error from django. -
configuring django admin on elastic beanstalk
I am having a hard time configuring django admin to work on elastic beanstalk. I tried everything but it's still not working. when I click on admin or my flag pages I get Server Error (500). I have created a folder in my project called management in the root of my project, inside that I created another folder called commands and a file called createsu.py here is the content of the createsu.py from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User class Command(BaseCommand): def handle(self, *args, **options): if not User.objects.filter(username="admin").exists(): User.objects.create_superuser("admin", "admin@admin.com", "admin") self.stdout.write(self.style.SUCCESS('Successfully created new super user')) in my .config file I added this like of code 03_createsu: command: "python manage.py createsu" leader_only: true after eb deploy and refreshing elastic beanstalk console when I try to go to the webpage I still get the same error. all my other pages are working, static files are working fine except my admin and flag pages because they are connected to the admin. I have been struggling with this for a week now. can someone please help me please. -
Submit and still stay in the same url
I want to Add data into database when I click "Submit" and show data in this html. But When I click, the url will add /submit_skill/ after so when I want to add more data, I will go back before url. I want to Add data , show data and not change url. this is my code HTML : {% if messages %} <ul class="messages"> {% for message in messages %} <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> {% endfor %} </ul> {% endif %} <form action="submit_skill/" method="POST" enctype=multipart/form-data> {% csrf_token %} Add Skill : <input type="text" name="skill_name" placeholder="Skill"> Select Skill Type : <select class="" name="skill_type"> <option value="1">Developer</option> <option value="2">Network</option> <option value="3">System</option> <option value="4">Database Analysis</option> </select> <button type="submit" name="button" id="btnAdd" >Add</button> </form> // show Data in the new row of the tabel <br> <table border="3"> <thead> <th>Skill Name</th> <th>Skill Type</th> </thead> <tbody> {% for skill in Skill %} <tr> <td>{{skill.skill_name}}</td> <td>{{skill.skill_type}}</td> </tr> {% endfor%} </tbody> </table> view.py def submit_skill(request): skill_name = request.POST["skill_name"] skill_type = request.POST["skill_type"] if skill_name: skill = Skill(skill_name=skill_name,skill_type=skill_type) skill.save() else: messages.error(request, all_skill) return HttpResponseRedirect(reverse("index")) all_skill = Skill.objects.all() context = { 'Skill': all_skill, } template = loader.get_template("addskill.html") return HttpResponse(template.render(context, request)) I try to use "HttpResponseRedirect/reverse" … -
Convert QuerySet with calculate field to one or more json basead from key
I'm trying convert a QuerySet in a json to use with chartjs, but I've some problems with the convertion. eg: _queryset = CheckOut.objects.filter(date_service__year = this_year).values_list('date_service__month').\ annotate(total=Sum('profit')).order_by('date_service__month') dt = _queryset if a print this variable "dt", in template {{ dt }} I've this values printed <QuerySet [(8, Decimal('300.00')), (9, Decimal('729.00'))]> How I do to separate: month and total(from annotate) in two json, like this: [8,9] <- month [300, 729] <- total price -
Django Rest Framework Url Field Serializer
I have a model named File which contains a field named 'url'. class File(models.Model): """ Generic File model """ filename = models.CharField(max_length=500) url = models.URLField() Now if I pass this URL - 'https://s3.us-east-2.amazonaws.com/xyz/2018-09-25_17:39:16.80 (1).pdf' Note the space in the url before (1). The model serializer gives an error stating that the url is invalid. Do I need to encode the url myself by replacing the space with '%20' -
how to get one key and value from a json in python?
i am getting a data in response when i hit the API url in django, i want to get content_id fron that data to check its already exists or not? how to iterate the certain key and and its value? r.json() = { "code": 200, "status": "OK", "data": [ { "cart_id": "36", "content": [ { "price": "100", "price_id": "1", "code": "USD", "symbol": "$", "name": "Carol of the Bells SATB - arr. Jay Rouse", "content_id": "17408" } ], "poster_url": "http://devstudio.cnedocent.com/img/No-Image-Vertical.png" } ], "msg": "Contents Found!" } -
Revert back to the default Django admin template
I recently decided to style the Django Admin dashboard with Bootstrap. After a successful attempt, I wanted to switch back to the way it looked before adding bootstrap so I removed the boostrap_admin from the INSTALLED_APPS. However, when I restarted the server, the template was all messed up. -
What are the limitations on deploying a tkinter gui as a web app?
I have written a tkinter gui in python which involves access to image and excel files. It also has a quite a few buttons and frames to deal with. I built the gui using the pillow library for images, and the openpyxl and pandas library for dealing with excel. I also used the pdf2page library, but I already have a tool to convert pdf to png. Is there a way I can deploy my gui as a web app or run it on a website? If not, is there someway I can recreate a similar interface with the same underlying python code? (that is the code not used to make the tkinter widgets) I'm planning on using the Django framework - - or something easier - - and A2 web hosting (or similar quality web hosting)