Uploading images/file in Django in production mode - django

I am a noob in Django and I am about to deploy my first site in Django. I have a Profile model in my models.py file which has profile_pic attribute which will store the profile pic of the user. It is working well when upload the image in the development mode,ie, when DEBUG=True. But what changes do I have to make in the urls.py so that users can easily upload their profile picture even after deploying my site. Any code snippetor examples or some link would be very helpful.

Related

django app in cpaned doesn't upload pictures that I upload from django admistration page

after I deployed my django app to cpanel it doesn't save pictures that I upload it from django adminstration page
Not: all data I enter it's save it and can return it to template but pictures not upload them
How I can solve this problem?
I think, in models you should use,
your_variable_name = models.ImageField(upload_to='photos/%Y/%m/%d', blank=True)
and if this solution doesn't work, try posting your code here.

Django Admin CSRF issue on Cloud Sutdio

I am learning Django through Django official documentation on Cloud Studio,which can let people develop website online.However,a CSRF issue occurred when I tried to log in the Admin page Django carried originally.I didn't change anything in admin.py
enter image description here
enter image description here

Django: linking users to models in an App (new to django><)

I am quite new to django, I know little terms... so it will be appreciated if you would answer more specifically how to implement. <3
I am working on a web development assignment about an image sharing platform. functionality involves users upload, download, delete and search images, etc.
recently I have implemented 'allauth' plugin to my site so that users can login in to the site, also I created an app called 'AllImages' with a model - 'Image'.
MY QUESTION IS:
How can I link the users to 'AllImages' and 'Image', so that the system knows who uploaded a particular image.
because I want to only let the uploader himself being able to delete his image
I really know nothing about the plugin, its just done by someone haha....
this is the allauth plugin
In your Images model add a foreign key field to user.
from django.contrib.auth.models import User
Further you can query something like..
Images.objects.filter(user=logged_user) to get all images of this particular user.
Django auth User

django ckeditor running into unexpected errors

I am using django-ckeditor python package in my django app (django 1.11 + python 2.7). I have integrated it with s3 and it is hosted on Heroku. So far everything runs smooth.
Earlier I had an issue that non admin user could not upload images to server thus can not use any images as a part of their content. I fixed it by overriding ckeditor's browse and upload view. When i tested it it was working just fine. I pushed it to production.
Now none of my user can use ckeditors image upload or browse feature. when I try it, (as an admin or as regular user) it works. some users reported that app crashes, some said image wont show up despite uploading to server (also I can't see it in my s3 bucket.)
other images are working well with s3 for all users. but ckeditors images are working only for me, no matter which machine or which role I try as.
I also checked heroku apps, but they are not helpful at all.
Does anyone have idea any guesses why this could be happening.

How to upload an image in Django

I'm creating a new app in django environment. I want to upload image of user when he/she sign-up's in my app and i want to use the same image when he/she posts any comment in my app. So how to integrate image-uploading code into my app code?
You should be using UserProfile as has been answered here Django user profile and have the ImageField in there.
Then create a ModelForm for the UserProfile and render it wherever you want the user to setup their profile and add a user image. The Model form will render the ImageField as a file upload field and have default handles for it. Make sure you have MEDIA_URL configured in your settings.py. You would also need PIL installed in your path for the image upload to work.
You can access the UserProfile instance for your user doing user.get_profile in your templates and as a callable elsewhere.