These are chat archives for django/django

20th
Feb 2018
djangoReactGuy
@SanskarSans
Feb 20 2018 01:44
anyone have experience with django oscar
Nagaraj-Sambra
@Nagaraj-Sambra
Feb 20 2018 12:00
can anyone tell me how to store images in local folder ?
Django
Sadhr
@Sadhr
Feb 20 2018 12:09
@Nagaraj-Sambra Hello first you need to create a foulder in the main of your project called static that foulder can contain CSS and JS and IMAGES in this foulder you can put you images there or create another foulder on it for all your picture and then go to settings in your project and create the path of your static foulder like that : Search for BASE_DIR in the top of settings file and create another variable for the static path : STATIC_DIR = os.path.join(BASE_DIR, 'static') and in the bottom of settings file under STATIC_URL = '/static/' create a list STATICFILES_DIRS = [STATIC_DIR] now everithing its gonna be good for you
Nagaraj-Sambra
@Nagaraj-Sambra
Feb 20 2018 12:11
@Sadhr i got it, after doing all this, how to access those images in views.py ?
Sadhr
@Sadhr
Feb 20 2018 12:20
@Nagaraj-Sambra Okay if you wanna put the image in the css you can use the normal way url(/static/images/sample.jpeg) and if you wanna use the image directly in the html foulder you will call in the top of you html after <!DOCTYPE html> call {% load load staticfiles %} and in the image tag do that <img src='{% static "images/here_your_image.jpg" %} I hope this explination helping you
Ferruccio Balestreri
@ferrucc-io
Feb 20 2018 15:19
hey there!

i need help with a view. I have a User model which is the django standard that is extended by this

user_fr = models.OneToOneField(User, on_delete=models.CASCADE)
age = models.IntegerField(3, null=True)

So i'm inside a view and want to access the "age" using the request.user, but request.user.photo and request.user.user_fr.photo both don't work

It should be extremely easy and obvious how to solve this, but I can't 😂
Ferruccio Balestreri
@ferrucc-io
Feb 20 2018 16:10
okay fixed it
Mehmood Deshmukh
@meshde
Feb 20 2018 16:11
How?
Umar Sohail
@UMAR-SOHAIL
Feb 20 2018 19:53
How can i make a view function that checks that user is not submitting an empty comment.
Luke-VideoLibre
@LukeVideo
Feb 20 2018 20:18
Check it's length.
Sanjeev Sharma
@thesanjeevsharma
Feb 20 2018 20:29
if request.method == 'POST':
form = Campus_Ambassdor_Form(request.POST)
form.email = request.POST['email']
form.phone = request.POST['phone']
form.name = request.POST['name']
form.college_name = request.POST['college_name']
form.college_address = request.POST['college_addr']
form.ca_code = request.POST['ca_code']
form.reason_ca = request.POST['textarea']
print(form.name,form.phone,form.email,form.college_name,form.college_address,form.ca_code, form.reason_ca)
if form.is_valid():
page = form.save(commit=False)
email_id = form.email
phone = form.phone
This form works. I am getting values in the back-end but form.is_valid() fails. and the else block gets executed. Any idea?