django-views

Validate Multiple files in django

笑着哭i 提交于 2021-01-29 08:13:57
问题 I want to allow some certain file types to be uploaded. I wrote the below code for one certain file, it worked. def validate_file_extension(value): if not value.name.endswith('.zip'): raise ValidationError(u'Error message') but I want to allow more than one files, so I set those files in settings_dev, and wrote the below code, but not working. def validate_file_extension(value): for f in settings_dev.TASK_UPLOAD_FILE_TYPES: if not value.name.endswith(f): raise ValidationError(u'Error message'

STATIC(CSS AND JS) FILES ARE NOT WORKING AFTER UPLOADING WEBSITE ON HEROKU

倖福魔咒の 提交于 2021-01-29 07:24:31
问题 I have just uploaded my website on heroku, the css and javascript files works perfectly on localhost but doesn't work after deploying. I also made sure to run this command python manage.py collectstatic which i did both in the production and development environment but doesn't still solve the problem. I have included the necessary codes that would be useful, i have also included the images of both instances and my project directory Settings.py STATIC_URL = '/static/' STATIC_ROOT = os.path

Stream multiple files at once from a Django server

你。 提交于 2021-01-29 06:12:00
问题 I'm running a Django server to serve files from another server in a protected network. When a user makes a request to access multiple files at once I'd like my Django server to stream these files all at once to that user. As downloading multiple files at once is not easily possible in a browser the files need to be bundled somehow. I don't want my server having to download all files first and then serve a ready bundled file, because that adds a lot of timeloss for larger files. With zips my

Django + HTML: Why does my if condition in my template fail even thought I havent submitted interest?

心不动则不痛 提交于 2021-01-29 06:11:59
问题 Django + HTML: Why does my if condition in my template fail even thought I havent submitted interest? As you can see from my views.py i have already indicated that if you have submitted interest, you will get the message that you have submitted the interest, otherwise the button 'submit interest' will be shown. Why does it not work then? views.py def detail_blog_view(request, slug): context = {} #need to import a package get_object_or_404. return object or throw 404 blog_post = get_object_or

Django Add Field Error to Non-Model Form Field

牧云@^-^@ 提交于 2021-01-29 05:50:44
问题 Can anyone help me understand how to properly send a field error back to a non-model form field in django that is not using the standard django form validation process? Rendering the form again with error and user data still entered for correction and resubmission? Example html for a simple username field that is validated on the model level: <!--form--> <form id="profile" class="small" method="POST" action="{% url 'profile' %}"> {% csrf_token %} <!--Username--> <label for="username">Username

Correct if/else statement syntax for django templates

有些话、适合烂在心里 提交于 2021-01-29 04:49:46
问题 I have a dating app and I need to create a link that is underneath each profile that a user matches on. Then, that link should pass their user id into the template so that messages are only displayed between the current user and that particular user based on the user id. I am having trouble here with the syntax of if/else statements within the Django template. How would I go about doing this? **base.html/href messages link ** <li class="nav-item"> <a class="nav-link" href="{% url 'dating_app

How can I automatically add the blogpost author into the member list?

試著忘記壹切 提交于 2021-01-28 08:00:43
问题 Everytime a blogpost is added, a memberlist will be generated. How do I automatically make it such that the author of the post will be included in the member list? I have added the create blog view models.py class BlogPost(models.Model): chief_title = models.CharField(max_length=50, null=False, blank=False, unique=True) body = models.TextField(max_length=5000, null=False, blank=False) members = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name="members") author =

NoReverseMatch at / list

北城以北 提交于 2021-01-28 03:59:06
问题 I tried get dynamic link Error: NoReverseMatch at / Reverse for 'new_single' with keyword arguments '{'pk': 1}' not found. 1 pattern(s) tried: ['single/'] Code: view: {% for new in news %} {{ new.id }} <h2><a href="{% url 'new_single' pk=new.id %}">{{ new.title }}</a></h2> {% endfor %} urls: urlpatterns = [ url(r'^$', views.news_list, name='news_list'), url(r'single/<int:pk>', views.new_single, name="new_single"), ] views: def new_single(request,pk): new=get_object_or_404(News,id=pk) return

How to pass variable in url to Django List View

扶醉桌前 提交于 2021-01-28 03:51:02
问题 I have a Django generic List View that I want to filter based on the value entered into the URL. For example, when someone enters mysite.com/defaults/41 I want the view to filter all of the values matching 41. I have come accross a few ways of doing this with function based views, but not class based Django views. I have tried: views.py class DefaultsListView(LoginRequiredMixin,ListView): model = models.DefaultDMLSProcessParams template_name = 'defaults_list.html' login_url = 'login' def get

django search page not found error

白昼怎懂夜的黑 提交于 2021-01-28 03:42:57
问题 I am stuck at a point where i should be able to type in a search query on the page and it django should get back a list of matching pages if any. But it doesnt show me any pages, even though its there, and gives me an erros. Suppose I have one page whose content is one, when i search, i get this error: Page not found (404) Request Method:GET Request URL:http://xxx.x.x.x:8000/search/csrfmiddlewaretoken=W6n1O1vQCMyDojxEkR4mPnRrVz9lYVt1&q=one No FlatPage matches the given query. Please point me