minimal-django-file-upload-example
minimal-django-file-upload-example copied to clipboard
Implementation of the project
I have implemented the sample project. But cannot see the results after clicking upload button. See attachment. https://drive.google.com/drive/folders/19yIF1S4YnLbUuJGvkV7k8av5jamWKikm?usp=sharing
Hi!
Which upload-example version are you using? I assume v2.0 but could you confirm?
The http 405 error refers that the method is not allowed. This probably is a problem with routes.
Did you customize the example code in any way?
To which URL does your upload form point to? I mean, what is the value of action attribute of your form element?
Hope this helps you further.
Hi! Thanks for the quick response. Yes it is Django 2.1 . If you will check the same drive link, I have attached the zip of the project. https://drive.google.com/open?id=19yIF1S4YnLbUuJGvkV7k8av5jamWKikm
(tmp_yr0cz.zip , password is in the zip_pass.txt file) Only difference between your project and my implementation is that your project name is "myproject" within which there is myapp. In mine, the project name is "app" and app within it is "myapp".
I haven't customized it in anyway yet. I dont see a form action on the button in your code either. Am I missing something?
Thanks!
I had two more questions :
- In the settings.py , when I add below, MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/'
Am I also supposed to create a media folder for it? If so, what should be the absolute path for it.
-
Within models.py,
class Document(models.Model): docfile = models.FileField(upload_to='documents/%Y/%m/%d')
Am I supposed to have a documents folder already? If so, what should be the absolute path for it.
Unfortunately I do not have much time to look into it, but there is some that could take you further:
- The most recent upload-example is for v2.0. There is no upload-example for v2.1 yet. You have Django v2.1 so it might cause issues.
- Does your line 21 in myproject/urls.py point to
myapp.urlsorapp.urls? - Does your situation change if you rename your
appdir tomyapplike in the upload-example? - By
actionattribute of the form element I refer to this line. It does not have much to do with the button. - About
upload_toparameter, the documentation says "the string value will be appended to your MEDIA_ROOT path". The documentation is your friend in these matters.
Hi,
found the issue. Please update your myproject/myproject/urls.py with a home redirector (third line). That way, after upload, it will redirect to the same page.
urlpatterns = [ path('admin/', admin.site.urls), path('myapp/', include('myapp.urls')) path('',views.list, name='list') ]
thanks a lot!
Hi, great! Let us keep this issue open, as a reminder, until that thing gets fixed. Thanks!
Yeah Sure! This is great help. Thanks!