Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Using django-photologue to assign single image to a model
I'm working on my first project in django, and the first part of it is a blog app. I've installed django-photologue which seems very useful for the intended purposes for later apps. Although this app will be used extensively later for posting galleries in other apps, assigning single photo to a model still eludes me. Namely, what I want is to assign a single image to each post, which will be a featured image to show on generated list of posts. I've tried a couple of different way, always resulting in same error. First attempt: class Post(models.Model): ... image = models.ForeignKey(Photo, related_name='posts') ... Migrating worked and the option appeared in post admin. It showed a drop down list of all images in photologue library. I tried to create a test post in admin and it resulted in a ProgrammingError column posts_post.image_id does not exist LINE 1: ..., "posts_post"."created", "posts_post"."updated", "posts_pos... From what I understand, trying to create a relation falls through because it lacks the image_id column to assign the pk (although I'm not 100% sure that's the problem). I experienced this same error when I tried creating categories for posts, which I solved using ManyToManyField so I gave it … -
CSRF token missing or invalid
I have this error: "CSRF Failed: CSRF token missing or incorrect." and according to many answers, this is the way to fix it: jQuery.ajax({ url: '/api/v1/order/'+orderid+'/', type: 'PUT', data: { csrfmiddlewaretoken: "{{ csrf_token }}" } }); However, in my case, it doesn't. I always get that HTTP 403 error. I am sure the token gets sent, Firebug shows me csrfmiddlewaretoken=jI8P6LfZ1p1OqIv3ikOU1VPFePjFjFnD in the PUT request. -
Django turn off redirect after login
Is there a way to completely turn off redirection after user login? I just can't find out how to do this... I just don't need any additional queries after login, because it's happening in modal window. I tried to set LOGIN_REDIRECT_URL = None or LOGIN_REDIRECT_URL = '' in settings, none of this works. Am I missed something? -
using SSL with nginx in a django app
This is my yo_nginx.conf file: upstream django { server unix:///home/ubuntu/test/yo/yo.sock; # for a file socket, check if the path is correct } # Redirect all non-encrypted to encrypted server { server_name 52.89.220.11; listen 80; return 301 https://52.89.220.11$request_uri; } # configuration of the server server { # the port your site will be served on listen 443 default ssl; # the domain name it will serve for server_name 52.89.220.11; # substitute your machine's IP address or FQDN charset utf-8; ssl on; ssl_certificate /etc/ssl/certs/api.ajayvision.com.chain.crt; ssl_certificate_key /etc/ssl/private/api.ajayvision.com.key; # max upload size client_max_body_size 75M; # adjust to taste # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /home/ubuntu/test/yo/uwsgi_params; # the uwsgi_params file you installed } } All I want to do is implement SSL on my django app but when I open the domain, it opens up in normal HTTP port. Also when I open the domain using https, it says check your connection. Am I missing something in my conf file? -
How to list models (via single view), inherited from the one base model, that they are displayed in accordance with the implementation
For example I have next structure: class BaseModel(models.Model): title = models.CharField(max_length=100) user = models.ForeignKey(User, related_name='foo') def __str__(self): return self.title class OneModel(BaseModel): date = models.DateTimeField() class TwoModel(BaseModel): is_active = models.BooleanField(default=False) In my project BaseModel isn't abstract class. Help me with convenient pattern, how implement view and render template html page? I think need some single view, because BaseModel can have many forks. -
deploy python 3.5 and django 1.10 on windows
So I am using python 3.5 with django 1.10 and finished developing a small project and ready for deploy. Right now I have a Windows server 2012 R2 with IIS 8.5 already set up so I tried that first. I followed this tutorial but failed. I think it is because that I am using python 3.5 but the fastCGI 2.1 Gateway only support up to 3.4. Now I am wondering if there is alternative way to deploy on a local windows server with my version of python and django? I know Azure has good support for this but I have to do this locally. Thanks! -
Save base64 image in django file field
I have following input "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7YAAAISCAIAAAB3YsSDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA5JxJREFUeNrsnQl4FEX6xqcJJEAS7ivhBkMAQTSJ4h0QEQ+I90rAc1cOL3QBXXV1AV1dVwmrsCqQ9VwJ6HoC7oon0T8iEkABwRC5IeE+kkAIkPT/nfmSmprunskk5CDw/p55hu7qOr76api8/U11lWGaposQQgghhBBSSh26gBBCCCGEEEpkQgghhBBCKJEJIYQQQgihRCaEEEIIIYQSmRBCCCGEEEpkQgghhBBCKJEJIYQQQgihRCaEEEIIIYQSmRBCCCGEEEpkQgghhBBCKJEJIYQQQgihRCaEEEIIIYQSmRBCCCGEEEpkQgghhBBCKJEJIYQQQgihRCaEEEIII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LLyoRzVVGK+/fbbU6mUKi9btuzo0aPu0vXsoYce4tcVQFHYgBpA0V5++WUGAYvICy+8wCAAKAoLLQAUjYUWAAAiMgD8E/71CQBARAYAIjIAgIgMAERkAAARGQCIyAAAEJEBXAm+rgcAICIDwD9hFhkAQEQGACIyAICIDABEZAAAERkAiMgAABCRARCRAQAgIgO4ajzRAgCwtP0bQwAAAABEMYsMoGgstAAALG038H91AAAAQBQLLQAAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAEBEBgAAAIjIAAAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAAAiMgAAAAAiMgAAAEBEBgAAAIjIAAAAABEZAAAAICIDAAAARGQAAACAiAwAAAAQkQEAAIC59X8CDADxvKI1RWM5MQAAAABJRU5ErkJggg==" I want to save this file in file field. What can I do? models.py class SomeModel(models.Model): file = models.FileField(upload_to=get_upload_report) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) -
Django 1.9 using django sessions in two page forms
How can I use django sessions to have a user be able to start a form on one page, and move to the next page and have them complete the form? Ive looked into pagination and wizard forms, but dont get them at all. When I have one page with a small portion of a model im using - in forms - and another page with the rest of the model - forms.py with the rest of the model info - I can use the first form perfectly. But when I move to the next page, i get an error saying (1048, "Column 'user_id' cannot be null"). My best guess is to use django sessions to fix this issue. I don't want the user to have to put in their username and password a second time to get this to work. Any ideas? -
password field is showing password in plain text
I have used django allauth for user registration and login system. I could show the form by simplifying the lines of code using for loop. I got the right field type(TextInput and PasswordInput) for each field too. However the password field which has PasswordInput shows password in plain text. How can i resolve this? my signup page(account/signup.html) <form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}"> {% csrf_token %} {% for field in form.visible_fields %} <div class="form-group"> <label for="{{ field.id_for_label}}">{{field.label}}</label> {{ field.errors.0 }} <input type="{{field|input_type}}" name="{{ field.name }}" class="form-control" id="{{ field.id_for_label}}"> </div> {% endfor %} </form> filters.py from django import template register = template.Library() @register.filter('input_type') def input_type(field): print('field',field.field.widget.__class__) return field.field.widget.__class__.__name__ How can i show password in dot? -
Set value in enum field
In django, you should use this as an enum field in your model (if I understand correctly, I am not working that long with Django): class Car(models.Model): TYPE = ( ('SUV','race') ) type = models.CharField(choices=TYPE, default='SUV', max_length=20) Later, in a filter, I can use this: suvs = models.Car.objects.filter(type='SUV') But this means a simple typo (SUB instead of SUV) can lead to an error, which isn't tackled by the code. Is there a way around this? Something perhaps like suvs = models.Car.objects.filter(type=models.Car.TYPE.SUV) -
Django: complex Formset validation, self.instance value makes no sense
I'm trying to overwrite the clean method on a formset. As the documentation proposes, I wrote my own BaseFormSet and overrode it's clean method. Some of the values of the FormSet depend on values from the parenting model form. The model is an Entry in an application that holds working time. An Entry applies to a day and there can only be one Entry, however an Entry can have several Shifts. As you can imagine, the model form is for the Entry, the FormSet is for the Shifts. So the Entry is the parent, the Shifts are the children. In order to validate a Shift, I need to access the parent Entry. I tried to do so by calling self.instance from within the clean method. self in this case would be the FormSet. However, the content of self.instance is always an Entry for the current day, that is lacking it's owner. If I'm trying to add an Entry for the 4th of January, self.instance should be for that date. However, when I access self.instance, the result is an entry for today. However the form for the Entry is valid. All values are entered correctly. There should be an owner. My … -
Query Django's HStoreField values using LIKE
I have a model with some HStoreField attributes and I can't seem to use Django's ORM HStoreField to query those values using LIKE. When doing Model.objects.filter(hstoreattr__values__contains=['text']), the queryset only contains rows in which hstoreattr has any value that matches text exactly. What I'm looking for is a way to search by, say, te instead of text and those same rows be returned as well. I'm aware this is possible in a raw PostgreSQL query but I'm looking for a solution that uses Django ORM. -
Navbar over extend block content, how to solve?
I am using django and bootstrap, but I am having a small problem that I can´t solve. The problem is the navbar on base.html is over the div on profile.html. When it should not be. See the images to clarify the problem. The files: Base.html <!DOCTYPE html> {% load staticfiles %} <html> <head> <link href="{% static 'css\bootstrap.min.css' %}" rel="stylesheet"> </head> <body> <nav class="navbar navbar-default navbar-fixed-top" role="navigation"> <a class="navbar-brand" href="#">MyTweets</a> <p class="navbar-text navbar-right">User Profile Page</p> </nav> <div class="container"> {% block content %} {% endblock %} </div> <nav class="navbar navbar-default navbar-fixed-bottom" role="navigation"> <p class="navbar-text navbar-right">Footer </p> </nav> <script src="{% static 'js/bootstrap.min.js' %}"></script> </body> </html> Profile.html <!DOCTYPE html> <!--esse extends significa que ele vai entrar no bloco definido no arquivo base.html--> {% extends "tweets/base.html" %} <!--definicao dos blocos, ou seja, tera o mesmo header, body ..., o que muda eh o content--> {% block content %} <div class="row clearfix"> <div class="col-md-12 column"> <!-- a classe well ou wellbox, da o efeito de insercao--> {% for tweet in tweets %} <div class="well"> <span>{{ tweet.text }}</span> </div> {% endfor %} </div> </div> {% endblock %} When I render I get this: How do I separate them? Each one is a diferent container I dont understand … -
Django: CSRF issue with Microsoft Edge and IE11
I have a CSRF token issue that only occurs in MS Edge and IE11 - it works fine in Chrome, Firefox and even IE9. The problem only occurs when doing Http post via Ajax. It gives me Http403 forbidden error. I have followed the guide in Django here: https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/ Do I need to add some extra headers for IE11 / MS Edge? Has anyone else encountered this problem? -
Python-Django.Response the text of error
How can i response the text of validation error to my template with ajax? def create_user(request): if request.method == 'POST': is_super = True if request.POST.get('is_super') in 'false': is_super = False if request.POST.get('password') == request.POST.get('confirm'): user = User.objects.create(first_name=request.POST.get('first_name'), last_name=request.POST.get('second_name'), username=request.POST.get('username'), is_superuser=is_super, date_joined=datetime.now()) user.set_password(request.POST.get('password')) user.save() else: raise forms.ValidationError("Passwords doesn't match") return HttpResponse('') -
filter tags of django-taggit in Django' Queryset
Having the following models: class Post(models.Model): title = models.CharField(max_length=250) tags = TaggableManager() and the data are: **post.title** **post.tags** Django By Example python,django,web Who was Django Reinhardt python,django, Test-Driven Development with Python python,web Python for Data Analysis python,data Learning Python python Programming Python python Automate the Boring Stuff with Python python I try to code below >>> alist=Post.objects.filter(tags__name__in=["data","python"]) >>> for i in alist.annotate(sam_tags=Count('tags')): ... print(i.sam_tags) ... print(i) ... 1 Django By Example 1 Who was Django Reinhardt 1 Automate the Boring Stuff with Python 1 Test-Driven Development with Python 1 Learning Python 2 Python for Data Analysis 1 Programming Python >>> alist[0].tags.all() [<Tag: django>, <Tag: python>, <Tag: web>] >>> slist=alist.annotate(sam_tags=Count('tags')) >>> slist[0].tags.all() [<Tag: django>, <Tag: python>, <Tag: web>] >>> slist[0].sam_tags 1 >>> why is the value of slist[0].sam_tags (post:Django By Example) equal to 1? I think the post object of (post:Django By Example) has three tags [python,django and web] after reading the Django's documentation. https://docs.djangoproject.com/en/1.10/ref/models/querysets/#count It said that Count(expression) returns the number of objects that are related through the provided expression. so the code >>>alist[0].tags.all() [<Tag: django>, <Tag: python>, <Tag: web>] shows there are three tags in alist[0].tags, >>> slist=alist.annotate(sam_tags=Count('tags')) >>> slist[0].tags.all() [<Tag: django>, <Tag: python>, <Tag: web>] >>> slist[0].sam_tags 1 … -
Error loading MySQLdb module: No module named 'MySQLdb'
I have tried a lot to solve this issue but I did not solve it. I have searched a lot on google and stackoverflow, no option is working for me. Please help me. Thanks in advance. I am using django 1.10, python 3.4. I have tried : pip install mysqldb. pip install mysql. pip install mysql-python. pip install MySQL-python. easy_install mysql-python. easy_install MySQL-python. Anything else left ? C:\Users\benq\Desktop\dimo-develop\Project>python manage.py runserver Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0332D348> Traceback (most recent call last): File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 25, in <module> import MySQLdb as Database ImportError: No module named 'MySQLdb' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run autoreload.raise_last_exception() File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception six.reraise(*_exception) File "C:\Python34\lib\site-packages\django\utils\six.py", line 685, in reraise raise value.with_traceback(tb) File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "C:\Python34\lib\site-packages\django\__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Python34\lib\site-packages\django\apps\registry.py", line 108, in populate app_config.import_models(all_models) File "C:\Python34\lib\site-packages\django\apps\config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 2254, in _gcd_import File "<frozen importlib._bootstrap>", line 2237, in _find_and_load File … -
Django filter-save QuerySet
I've a django model:- class ModelA(models.Model): flag = models.BooleanField(default=True) Next, I query it:- obj = ModelA.objects.filter(flag=True) Now, I change the flag of first object. obj1 = obj[0] obj1.flag = False obj1.save() Now, when I get obj[0] again, it returns me the 2nd object of the filtered query. Why? -
Django multi database - how to recreate only default database
I'm having this problem: I have multiple databases in Django 1.8 (with REST framework) application. I want during my tests (./manage.py test) to only recreate 'default' database before every test and only create first time second database (or not, if it exists). I know that one way to do this is to use ./manage.py test with parameter --keepdb, but it stops recreating all the databases and I only want to stop recreating for only one database. So, it's possible? Thanks in advance for any help! -
django-oscar RuntimeError: conflicting models
Version Info: Python 2.7, Django 1.9, Oscar Commerce - VERSION = (1.3) I am trying to customize Products and few other models in the catalogue app following the documentation. I have forked catalogue app (to myproject/forked_apps/catalogue) as per documentation documentation and did this in models.py: from django.db import models from oscar.apps.catalogue.abstract_models import AbstractProduct class Product(AbstractProduct): is_active = models.BooleanField(default=False) from oscar.apps.catalogue.models import * I have already included the modified catalogue app, in the INSTALLED_APPS in settings.py as an argument for get_core_apps function, as stated in docs (so my local app is replacing the original app from Oscar). INSTALLED_APPS = [ ... ] + get_core_apps(['forked_apps.catalogue']) Migrations are also copied from oscar.apps.catalogue to my local app. When I'm trying to make migrations I'm getting this error all the time: RuntimeError: Conflicting 'product_product_options' models in application 'catalogue': <class 'oscar.apps.catalogue.models.Product_product_options'> and <class 'forked_apps.catalogue.models.Product_product_options'>. I tried to remove all migrations from my local catalogue app (the I copied before from Oscar app), then it works, but all new migrations are created in Oscar source code folder, but I need them to be in my project... How do I get over this error ? -
Raw file in django, if i use request.files it gives me i/o stream (incorrectly parsed format) i want to open the raw file and parse it.
i am trying to browse and open a .msg or .eml file in a django application. I used forms and request.files but the stream provided in octet format. i want to get the raw file object and open it as normal file later parse it. i can share the code. -
Django redirect after logout
I'm using Django and to authenticate my user, I have a custom OAuth2 provider. I had to write the login and logout view myself because they are doing some very specific things. I would like to be redirected to the same url after logout. If you are on a page that require to be authenticated, I would like to redirect to the homepage. I didn't find any resource to know if a view/endpoint is using the decorator login_required -
django(gunicorn) file upload do not work
I am trying to migrate my app to docker containers, but met the problem uploading files with django forms. Everything works just fine, but when I try to upload any file from forms in my app I get nothing, like multipart/form-data is not set in html form tag. But it set and everythings works if I install application directly with no dockers. Anyways here is my configs, I hope somebody can help me. Here is my docker-compose.yml version: '2' services: db_postgres: build: context: . dockerfile: dockerfiles/docker-postgres/Dockerfile args: - db_user=username - db_name=databasename - db_pass=password environment: LC_ALL: C.UTF-8 app: restart: always build: context: . dockerfile: dockerfiles/docker-app/Dockerfile links: - db_postgres:db_postgres nginx: restart: always build: dockerfiles/docker-nginx volumes_from: - app ports: - "80:80" - "443:443" links: - app:applink Here is application Dockerfile: FROM ubuntu:16.04 RUN \ apt-get update && \ apt-get install -y python-pip python-dev build-essential python-virtualenv && \ apt-get install -y libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev && \ apt-get install -y libpq-dev libffi-dev && \ apt-get install -y libssl-dev git RUN mkdir app COPY requrements.txt /app RUN pip install --upgrade pip RUN pip install -r /app/requrements.txt ADD . /app WORKDIR /app VOLUME ["/app/staticfiles/", "/app/media/", "/app/protected/"] # I tried this but it seams no effect at … -
Django error local variable 'item_id' referenced before assignment
i got everytime this error, i have no idea how to solve this problem. i'm sending item id with jquery to connect conversation object. my view: def chatpage(request): if request.method == 'POST': item_id = int(request.POST['item_id']) return JsonResponse({'status': 200}) message_form = MessageForm(data=request.POST) if message_form.is_valid(): new_message = message_form.save(commit=False) new_message.conversation_id = item_id new_message.agreement_delivery_time = 12 new_message.save() else: message_form = MessageForm() conversation = Conversation.objects.get(id=item_id) messages = conversation.message_set.all() return render(request, 'templates/Chatapp/chat.html', {'message_form': message_form, 'conversation': conversation, 'messages': messages}) -
Django 1.9 Wizard Form example
I'm making a multipage form for user registration and am going to be using Django Wizard Form. Could someone provide me a complete example of how to use it? I'm looking for an example with models.py, forms.py, and views.py. Here is my models.py that I'm looking at working with: class UserProfile(models.Model): user = models.OneToOneField(User) first_name = models.CharField(max_length=100, blank=True) last_name = models.CharField(max_length=100, blank=True) email = models.EmailField(max_length=100, blank=True) company_name = models.CharField(max_length=100, blank=True, null=True) website = models.URLField(max_length=100, blank=True, null=True) phone_number = models.CharField(max_length=100, blank=True, null=True) country = models.CharField(max_length=100, blank=True, null=True) address = models.CharField(max_length=100, blank=True, null=True) def __str__(self): return self.user.username and here is my forms.py so far: class UserForm(forms.ModelForm): password = forms.CharField(widget=forms.PasswordInput()) class Meta: model = User fields = ('username', 'password') class UserProfileForm1(forms.ModelForm): class Meta: model = UserProfile fields = ('first_name', 'last_name') class UserProfileForm2(forms.ModelForm): class Meta: model = UserProfile fields = ('company_name', 'website', 'phone_number', 'fax_number', 'country', 'address')