last day (14 days later) » 

9:44 AM
1
A: Django: best way to handle foreign key requests in template pages

wencakisaAs long as you can access product.productimage_set, you can try to iterate it in your template and do not pass it as a view context. In your Django template: {% for product in product_list %} <div class="product-listing" style="display:inline"> {% for product_image in product.produc...

 
How would that work, isn't ._set server side?
 
You can also access it in your template. I forgot to write .all in my answer, now it is edited. See this: stackoverflow.com/questions/6217638/…
 
this works! but... it gives me 404
 
Where it throws 404? When you try to access your image.url ?
 
yes, I have one app so instead of /my_app/<view> I am just using /<view>. The url it provides is correct my_app/product/static/product_images/product_1/image_1.jpg
 
9:44 AM
Have you configured your MEDIA_ROOT in settings.py correctly? See this link, I think it will be helpful: docs.djangoproject.com/en/1.11/ref/models/fields/…
 
Well I am still in development... but I have seen that site and tried it previously to no avail
if it returned /static/product_images/product_1/image_1.jpg it would work
should I just modify the url method
honestly the file field storage is - to me - very poorly documented compared to the rest of django
neither that link or the managing files page really makes it clear how to handle the image media
?
 
10:05 AM
Can you send a photo of your 404 stacktrace?
 
I generalized my problem with product and product image
but I am using the words wohnungen
and bilder
 
I think the problem is coming from that <appname> before /static/...
 
that is the problem
 
try to fix the function that you use for uploading
and remove the <appname> in the beginning
 
ok
lemme try
 
10:09 AM
you can see in your second photo of the terminal
django access'
 
so /static/...
or static/...
 
"GET /static/wohnungen/style.css"
not wohnungen/static/wohnungen/style.css
static/ only, without the slash in the beginning
then try to upload a new image and then access your view to see if it renders
 
ok.. I made the changes but it somehow made the admin site not work
how do I delete all my models
and start fresh?
 
you can use flush
python3 manage.py flush
then you can run again
python3 manage.py migrate
in order to create a new fresh empty db
 
one sec I have to make a new admi >.<
 
10:13 AM
yeah, this too :D
python3 manage.py createsuperuser
 
ok
did that
added a product and an image to the product
same problem
 
is your image there really?
can you send a photo of your project folder structure
and more to your static folder
 
no, now my image is under root/static...
rather than root/my_app/static
>.<
 
what your upload_to method looks like now?
 
return 'static/wohnungen/bilder/wohnung_{0}/{1}'.format(instance.wohnung.id, filename)
hence why I had the app name in the first place. I think I tried it this way originally at some point
ug, why django make it so hard
:P
 
10:20 AM
docs.djangoproject.com/en/1.11/howto/static-files Have you gone through all of these steps?
Do your urlpatterns have routes for static files?
Because now the image is uploaded in the right place
you need to have one global static folder
with directories named <appname> in it
 
maybe? I say that because I defined my app_name and use relative static as done in the tutorial part 3
why
that makes no sense
then it defeats the purpose of modular
when everything is in a root
which is why we name space under static
which is local to the app
or am I missing something
cause I can dump all my files into one direcotyr, but that is ugly
I tried that a few days ago (adding + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))
but then the site doesnt lload at all
which again is not the best documentaiton in Django as it doesnt specify which urls.py file
the one under root? the one for myapp?
I dont?
who knows
either way pasting + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) after urlpatterns = [] in any or all of the files doesnt work
honestly that page is waaaaay to confusing. I do state of the art deep learning in genomics and god damn that single page is full of ambigiouity to the uniinitatied
and contradicteds with the tutorial
"Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg."
so I changed the helper function back so that files are uploaded to my_app/static/my_app/...
but this is not working
 
10:57 AM
i made a new question
0
Q: Django: understanding how to serve static files during deployment -- NOOB edition

SumNeuronI am struggling with getting my static files to work. Before one starts posting links to the docs, I have been to and read to the best of my having-completed-the-django-tutorial-level understanding the following links: https://docs.djangoproject.com/en/1.11/topics/files/ https://docs.djangoproj...

 

last day (14 days later) »