Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
display:'table' is not working as it supposed to be
I want the table to be visible only after the submit button clicks. But it's not staying on the screen as it is supposed to be. Once I click the submit button, the table comes up for a second and then again becomes invisible. Please let me know what I am doing wrong in my code. Also please let me know if there is any other way to do it. index.html <form action="#" id="form" method="post"> <div style="margin-left: 2rem;"> <!-- <input class="btn btn-primary" type="submit" value="Submit" id="btn" onclick="hide()"> --> <input class="btn btn-primary" type="button" value="Submit" id="btn" onclick="hide()"> </div> </form> <div style="margin-top: 4rem; display: flex; justify-content: center; align-content: center;"> <table style="display: none;" id="table"> <tbody> <tr> <th scope="row">Profile No. : </th> <td>{{ProfileNo}}</td> </tr> <tr> <th scope="row">Name : </th> <td>{{Name}}</td> </tr> </tbody> </table> </div> <script> function hide() { document.getElementById("form").submit(); let table = document.getElementById("table"); if (table.style.display === 'none') { table.style.display = 'table'; } } </script> -
Selecting items from a many to many field to link specific items in the list to a model in the admin panel
I am working on a recipe book app, and I currently have my models connected in this way: class Tool(models.Model): name = models.CharField(max_length=50) description = models.CharField(max_length=200) def __str__(self): return self.name class Recipe(models.Model): name = models.CharField(max_length=50) description = models.CharField(max_length=200) servings = models.IntegerField(default=1, blank=False) tools = models.ManyToManyField(Tool) def __str__(self): return self.name The admin panel input currently looks like this: Upon saving the data as shown in the screenshot, I get the following error: OperationalError at /admin/recipeBook/recipe/add/ no such table: recipeBook_recipe_tools Here is my admin.py, just incase it's useful: from django.contrib import admin from .models import Recipe, Ingredient, Instruction, Tool # Register your models here. class IngredientInline(admin.TabularInline): model = Ingredient extra = 2 class RecipeAdmin(admin.ModelAdmin): fieldsets = [ ('Information', {'fields': ['name', 'description', 'servings']}), ('Tools', {'fields': ['tools']}) ] inlines = [IngredientInline] list_display = ('name', 'description', 'servings') search_fields = ['name'] list_filter = ['servings'] admin.site.register(Recipe, RecipeAdmin) admin.site.register(Ingredient) admin.site.register(Instruction) admin.site.register(Tool) -
Django POST getlist for dynamic content
I a database I have a list of products. If they are need to be found = True they will appear in the screen : <h2>Shopping list</h2> <section> {% for market in markets %} <button class="collapsible">{{market.name}}</button> <div class="content"> <ul> {% for shopping in shoppings %} {% if shopping.marketplace.name == market.name %} <div id="conteneurs"> <div class="product"><label for="stock" class="control-label">{{shopping.name}}</label></div> <div class="stock"><input type="number" name="stock" value="{{shopping.quantitytobuy}}" id="stock"></div> <div class="checkbox"><input type="checkbox" name="found"></div> </div> {% endif %} {% endfor %} </ul> </div> {% endfor %} </section> <div id="validation"> <div class="validation"><input type="submit" value="Found"></div> </div> If I found the product I can check a box. I would like to recover the amount for the products where I check the box the quantity to can update the stock of them. I have no idea where to start : should I need to define a variable for the checkbox ? how do I recover the quantity with the associate product for all the line checked in the file views.py def shopping(request): marketplaces = Marketplaces.objects.order_by('name') products = Products.objects.all().filter(buy=True) template = loader.get_template('stock/shopping.html') context = {'markets' : marketplaces, 'shoppings' : products, } return HttpResponse(template.render(context, request=request)) -
Django / Access to previous or next instance from the same class
My app starts with Scene1 Here is my Models.py where Scenes are defined class Scenes(models.Model): name = models.SlugField('Scene name', max_length=60,unique=True) description = models.TextField(blank=True) fileGltf = models.FileField(null=TRUE, blank=False, upload_to="3dfiles/") record_date = models.DateTimeField('Scene date') manager = models.ForeignKey( settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.SET_NULL) prev = models.ForeignKey( 'self', related_name='next', blank=True, null=True, on_delete=models.SET_NULL) def __str__(self): return self.name The creation is ok. Then in views.py, let's say my current scene is : myScene=Scenes.objects.get(name=whichScene) If I want to list all next scenes from this scene : scene_list=myScene.next.all() If I want to access to the previous scene, what is the correct syntax ? scene_previous=myScene.prev -
Load foreign model instances into queryset.values()
I have queryset that groups and aggregates some data: EmployeeAssessment.objects.all().annotate(month=TruncMonth('assessment_date')).values( 'month', 'assessed_employee', 'subject' ).annotate(average_score=Sum('scores__score') / Count('scores__score', distinct=True)) And because of .values() I get assessed_employee and subject as IDs rather than model instances I know that there are some similar questions here, but they're all talking about single relation, that can be reversed to get the needed data from related model. My problem is that I need to get two nested objects: "assessed_employee" and "subject". Both of them are ForeignKeys I use DRF serializer like this: class EmployeeAverageScoreSerializer(Serializer): month = DateField() assessed_employee = EmployeeSerializer() # <- ModelSerializer subject = AssessmentSubjectSerializer() # <- ModelSerializer average_score = FloatField() It is ok if I will have some subqueries or something, but I need a single queryset that still can be paginated. How can I load models by ID after applying ".values" or maybe what other way can I use to get that data without losing model instances in resulting queryset? -
No module named 'crispy_formsecommerce' error
I already installed crispy forms, and fixed settings. But raising an error. The Error: enter image description here My settings.py file: enter image description hereenter code here enter image description here my pipenv installed apps : enter image description here some template: enter image description here my forms.py: enter image description here Please help! -
How can i call class function thats insert row into db properly from my django template?
Hellow, I am noob and I make instagram followers scraper on Django. I make a function that should add 1 (only 1 cos it works really slow) new follower in to db which takes from already working sсraping functions and place it into class. class ListOfFollowers(ListView): model = Followers context_object_name = 'followers_of' template_name = 'insta/followers.html' def get_follower(self, username): loader = instaloader.Instaloader() loader.login('***', '***') profile = instaloader.Profile.from_username(loader.context, username) followers = profile.get_followers() followers_tuple = tuple(followers) i = random.randint(0, len(followers_tuple) - 1) login = followers_tuple[i].username photo = followers_tuple[i].get_profile_pic_url() url = f'https://www.instagram.com/{login}/' mutual_subscription = followers_tuple[i] in profile.get_followees() res = {'login': login, 'photo': photo, 'url': url, 'mutual_subscription': mutual_subscription} return res def add_followers(self): username = WhoFollow.objects.get(follow_on__contains=self.kwargs['follow_id']).title context = None while not context: try: context = get_follower(username) except: next context.update({'follow_on': self.kwargs['follow_id']}) res = Followers(context) res.save() def get_queryset(self): return Followers.objects.filter(follow_on=self.kwargs['follow_id']) function calls add_followers (try block is just because its not always working from 1st try) My models class WhoFollow(models.Model): title = models.CharField(max_length=255) def __str__(self): return self.title def get_absolute_url(self): return reverse('follow', kwargs={'follow_id': self.pk}) class Followers(models.Model): login = models.CharField(max_length=255) photo = models.ImageField(upload_to="photos/", blank=True) url = models.URLField() mutual_subscription = models.BooleanField(default=False) time_add = models.DateTimeField(auto_now_add=True) time_unfollow = models.DateTimeField(blank=True) follow_on = models.ForeignKey(WhoFollow, on_delete=models.PROTECT) def __str__(self): return self.login And my template {% extends 'insta/Base.html' %} … -
How to reduce size of input box in html used in django
Is there any way to reduce the size of the description box used below? I used it on a HTML template under a django project when I rendered the page the description box was huge. <div class="container-fluid"> <div class="card-body"> <form action="{% url 'create_post' pk=classroom.id %}" method="POST" enctype="multipart/form-data"> {% csrf_token %} <div class="form-group"> {{ post_form.title|attr:"class:form-control"|attr:"placeholder:Title"}} </div> <div class="container"> {{ post_form.description|attr:"class:form-control"|attr:"placeholder:Description" }} </div> <button type = "submit" class="btn btn-sm btn-primary m-1 pl-3 pr-3 float-right"> Post </button> <button id = "cancel-post" class="btn btn-sm btn-outline-dark m-1 float-right"> Cancel </button> </form> </div> </div> -
Web app such as libgen using Python and SQL?
I'm trying to make a webapp almost like the website libgen essentially using Python that can access a MySQL database and query and search through the database in order to find what they are looking for. I'm a bit stuck on how to approach this as I believe using Django as a framework to access the database would be good but I can't seem to understand how to connect the database (which I have locally) to the project. But then I would need to be able to move this online for hosting. I would really appreciate the help. -
Null value in column violates not-null constraint after deleting objects incorrectly
Help me please I don't know what's going on. I wrote some simple blog, where I could add posts and comments. It was working well. views.py: def add_comment_to_post(request, pk): post = get_object_or_404(Post, pk=pk) # calls the given model and get the object, type = <class 'blog.models.Post' if request.method == "POST": # if we posted data form = CommentForm(request.POST) if form.is_valid(): # if all fields are filled comment = form.save(commit=False) # create instance and return which not saved in database "Comment" <class Comment> comment.post = post # return Title comment.author = request.user comment.save() return redirect('post_detail', pk=post.pk) else: form = CommentForm() # type = <class 'blog.forms.CommentForm'> return render(request, 'blog/add_comment_to_post.html', {'form': form}) But when I added a function for deleting comments, that wrote me a mistake, like this: null value in column "approved_comment" of relation "blog_comment" violates not-null constraint views.py: def comment_remove(request, pk): post = get_object_or_404(Post, pk=pk) comment = get_object_or_404(Comment, pk=pk) print(comment) comment.delete() return redirect('post_detail', pk=post.pk) I think I deleted comment incorrectly. I don't understand how primary keys works, how comments and posts are related each other. And I don't understand how to understand it. -
django remove object from list that match query filter
At my Django application I have two lists. One list called keys and anotherone existing_keys: for key in keys: if Files.objects.filter(file_name=Path(key).name).exists(): existing_keys.append(key) while key in existing_keys: keys.remove(key) print(f'key {key} removed') How can I now remove all entries in keys that have a match with existing_keys? currently im always running into the following error: raised unexpected: ValueError('list.remove(x): x not in list') Thanks in advance -
Need to perform update method on writable Nested serializers in django
models.py class Product(models.Model): product_id = models.CharField(max_length=50,default=uuid.uuid4, editable=False, unique=True, primary_key=True) product_name = models.CharField(unique=True,max_length=255) class Client(models.Model): client_id = models.CharField(max_length=50,default=uuid.uuid4, editable=False, unique=True, primary_key=True) org = models.ForeignKey(Organisation, on_delete=models.CASCADE, related_name='org',null=True) product = models.ManyToManyField(Product,related_name='product') client_name = models.CharField(unique=True,max_length=100) .... serializers.py class Clientpost_Serializers(serializers.ModelSerializer): billing_method = Billingmethod_Serializers() product = Product_Serializers(many=True) def create(self, validated_data): billing_method_data = validated_data.pop('billing_method') product_data = validated_data.pop('product') billing_method = Billing_Method.objects.create(**billing_method_data) validated_data['billing_method'] = billing_method client = Client.objects.create(**validated_data) product = [Product.objects.create(**product_data) for product_data in product_data] client.product.set(product) return client def update(self, instance, validated_data): billing_method_data = validated_data.pop('billing_method') billing_method = instance.billing_method # product_data = validated_data.pop('product') # product = instance.product instance.currency = validated_data.get('currency', instance.currency) instance.currency_type = validated_data.get('currency_type', instance.currency_type) instance.first_name = validated_data.get('first_name', instance.first_name) instance.last_name = validated_data.get('last_name', instance.last_name) instance.description = validated_data.get('description', instance.description) instance.street_address = validated_data.get('street_address', instance.street_address) instance.city = validated_data.get('city', instance.city) instance.state = validated_data.get('state', instance.state) instance.country = validated_data.get('country', instance.country) instance.pincode = validated_data.get('pincode', instance.pincode) instance.industry = validated_data.get('industry', instance.industry) instance.company_size = validated_data.get('company_size', instance.company_size) instance.client_name = validated_data.get('client_name', instance.client_name) instance.contact_no = validated_data.get('contact_no', instance.contact_no) instance.mobile_no = validated_data.get('mobile_no', instance.mobile_no) instance.email_id = validated_data.get('email_id', instance.email_id) instance.client_logo = validated_data.get('client_logo', instance.client_logo) instance.client_code = validated_data.get('client_code', instance.client_code) instance.save() billing_method.billing_name = billing_method_data.get('billing_name', billing_method.billing_name) billing_method.description = billing_method_data.get('description', billing_method.description) billing_method.save() # product.product_name = product_data.get('product_name', product.product_name) # product.save() product_data = validated_data.pop('product', []) instance = super().update(instance, validated_data) for products_data in product_data: product = Product.objects.get(pk=products_data.get('product_id')) product.product_name = products_data.get('product_name', product.product_name) instance.product_data.add(product) instance.save() return instance When … -
Django makemirgations not updating database
When I make changes to models.py, I am expecting django to update the database structure for me when I run python3 manage.py makemigrations or python3 manage.py makemigrations appname. It doesn't detect any changes. I have had this issue once before and had to delete everything in the database to update it, which seems a bit drastic. What am I doing wrong? This is the new line I have just added: l3_interfaces = JSONField (py38-venv) [xxxxxx@xxxxxxn]$ python3 manage.py makemigrations No changes detected Contents of models.py from django.db import models #Generic for models from django.contrib.auth.models import User #Required for dynamic user information from django.forms import ModelForm #Custom form from jsonfield import JSONField #Unique order. Top of heirachy tree class Order(models.Model): order_name = models.CharField(max_length=100, unique=True)#, null=True, blank=True) #Unique name of order created_by = models.ForeignKey(User, related_name='Project_created_by', on_delete=models.DO_NOTHING) #Person who created the order created_at = models.DateTimeField(auto_now_add=True) #Date/Time order was created def __str__(self): return self.order_name #For CE router definition. Required for all orders. class Ce_Base(models.Model): #Hardware models of router ROUTER_MODELS = ( ('CISCO2901', 'CISCO2901'), ('ISR4331', 'ISR4331'), ('CISCO1921', 'CISCO1921'), ('ISR4351', 'ISR4351'), ('ISR4451', 'ISR4451'), ('ISR4231', 'ISR4231'), ('ISR4431', 'ISR4431'), ('ISR4461', 'ISR4461'), ) #Available regions in which the router can reside. REGION = ( ('1', '1'), ('2', '2'), ('3', '3'), … -
Show different pages based on user - django
I'm building a web app IMDB's like. Each (logged) user views the same exact homepage, but they can flag/unflag every movie they want to save them in a "seen list". I've done that but I've noticed that every user logged can view the other user's flagged movies. Of course this is a problem, so I'd like to build a page relative to each user, so that everyone would have different "seen films" page based on the movies flagged as seen. The main idea behind this, is that whenever a user adds a movie to the database, he can flag it as seen with a simple models.BooleanField in the model of the film. I have then another model "Seen" where there are all the movies flagged. models.py class Films(models.Model): ... seen = models.BooleanField(default=False) class Seen(models.Model): ... views.py films = Films.objects.all() for film in films: flag = 0 seen_films = Seen.objects.all() for _ in seen_films: if film.name == _.name: flag = 1 break if not flag and film.seen: act_seen = Seen(image=film.image, name=film.name, description=film.description) act_seen.save() I need to add that for the user, I use the default class provided by django: from django.contrib.auth.models import User I get that the error is everyone can … -
django/mysql table not found - django.db.utils.ProgrammingError: (1146, "Table 'trustline.authentication_user' doesn't exist")
i was trying to "makemigrations" for my project but whenever i do this, i got this error django.db.utils.ProgrammingError: (1146, "Table 'trustline.authentication_user' doesn't exist" and i have this line in settings.py AUTH_USER_MODEL = "authentication.User" here's the full error 1 2 -
Django admin - default value into a field via the filter selection
I'm trying to make a default value in my table via my selections in django admin. For example, I have 2 tables: model.py class Year (models.Model): year = models.IntegerField(primary_key=True, verbose_name='Year') def __str__(self): return str(self.year) class RFCSTForm (models.Model): id = models.AutoField(primary_key=True) year = models.ForeignKey(Year, verbose_name='Year', null=True, blank=True, on_delete=models.CASCADE) Then when I wanna create a new RFCSTForm and select via year's filters the value "2022", I want the field year will be filled by default with this value. is it possible in django model? -
display:'block' is not working as it supposed to be
I want the table to be visible only after the submit button clicks. But It's not staying on the screen as it is supposed to be. Once I click the submit button, the table comes up for a second and then again becomes invisible. Please let me know what I am doing wrong in my code. Also please let me know if there is any other way to do it. <div style="margin-left: 2rem;"> <input class="btn btn-primary" type="submit" value="Submit" id="btn" onclick="hide()"> </div> <div style="margin-top: 4rem; display: flex; justify-content: center; align-content: center;"> <table style="display: none;" id="table"> <tbody> <tr> <th scope="row">Profile No. : </th> <td>{{ProfileUID}}</td> </tr> <tr> <th scope="row">Name : </th> <td>{{Name}}</td> </tr> </tbody> </table> </div> <script> function hide() { let btn = document.getElementById("btn"); let table = document.getElementById("table"); if (table.style.display === 'none') { table.style.display = 'block'; } </script> -
Selenium authentication without sharing credentials
Isn't it bad to use actual credentials when testing log in pages with selenium webdriver? I am not very sure how security works but if someone is able to access the source code of the program together with its tests, then they would get a dummy test credentials that would still allow them to access the website. How do people go about this? -
Error 500 after 40 sec in Django WEB APP on IIS
I have a web app (DJango/ReactJS) that works perfectly on localhost, but after deploiment on IIS 10 some requests (http post) stops after 30, 40sec with state 500 (u have some inputs then a function gonna treat and calculate then return a resullt). i tried to change the timout in IIS settings but no diffrence ! i checked the logs on IIS, on windows's event viewer but no errors detected ! any sollution ? -
I cannot load the image in my template, I tried changing all upload file location and everything else and its the same with category field
models.py class product(models.Model): categoryChoices=[('food','Food'),('clothing','Clothing'),('books','Books'),('furniture','Furniture'),('others','Others')] product_name=models.CharField(max_length=40) product_decsription=models.CharField(max_length=100) pub_date=models.DateTimeField(auto_now=True) image=models.ImageField(upload_to='CharApp/images/',default='') address=models.CharField(max_length=200, default='') city= models.CharField(max_length=40) station= models.CharField(max_length=40) category= models.CharField(choices=categoryChoices,max_length=30) Views.py def index(request): donations=product.objects.all() return render(request,'CharApp/index.html',{'donations':donations}) Urls.py urlpatterns = [ path('admin/', admin.site.urls), path('',views.start,name='start'), path('home/',views.index,name='index'), path('upload/',views.productFormView), path('about/',views.about,name='about'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) Forms.py class productForm(forms.ModelForm): class Meta: model=product fields='all' widgets= { 'product_name': forms.TextInput(attrs={'class':'form-control'}), 'product_decsription': forms.TextInput(attrs={'class':'form-control'}), 'pub_date': forms.DateInput(attrs={'class':'form-control'}), 'image': forms.FileInput(attrs={'class':'form-control'}), 'address': forms.TextInput(attrs={'class':'form-control'}), 'city': forms.TextInput(attrs={'class':'form-control'}), 'station': forms.TextInput(attrs={'class':'form-control'}), 'category': forms.Select(attrs={'class':'form-control'}), I tried chnaging the img src call to a d.image.url call,and alot of other things it just doesnt load, its the same with category field, the view just doesnt load these two fields even tho they are available in the database -
How long class attributes live in python (Django)
I have this class in my Django app: class MyClass: property_1 = [] def add_elem(self): self.property_1.append(1) print(self.property_1) MyClass().add_elem() MyClass().add_elem() The output will be: [1] [1, 1] That means that when I start Django server, all the scripts(all app) are loaded to memory and as property_1 is a class attribute, every time I call add_elem(), I add a new '1' to the property? And property_1 will be cleaned only after restart server? -
Error H12 Heroku with Django bot scraping app
I have a bot made in Django and I want to run it on Heroku. The project's HTML template opens in Heroku just fine. This template has a form and a submit button. When I press the button, what is written in the form is sent to the main function of the bot and uses it during scraping. The problem is that the bot takes about 4 minutes to perform the functions and the Heroku router only executes requests for 30 seconds. I have searched for a thousand solutions on the internet but no matter how much I apply one after another I can't find it. I have also contacted Heroku support and they told me that I can use New Relic for long-runninf actions and use a background worker as well. I've tried setting both and I can't get around the H12 error either. Could someone tell me how to configure the worker and New Relic correctly? Many answers I find with this are old or I can't optimize it for my project. Thank you. (Sorry for my english btw) worker.py import urllib from redis import Redis from rq import Queue, Connection from rq.worker import HerokuWorker as Worker listen … -
How to loop through all the rows inside the list
I'm trying to iterate through the list of JSON, it just iterate only the first row How could I able to loop through all the rows inside the list This is my payload in browser [{AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…},…] 0: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…} 1: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…} 2: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…} 3: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…} 4: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…} here, what I tried @api_view(['POST']) def UserResponse(request): if request.method == 'POST': for ran in request.data: auditorid =ran.get('AuditorId') ticketid = ran.get('TicketId') qid = ran.get('QId') answer = ran.get('Answer') sid = ran.get('SID') TicketType = ran.get('TicketType') TypeSelected = ran.get('TypeSelected') agents = ran.get('Agents') supervisor = ran.get('Supervisor') Comments = ran.get('Comments') action = ran.get('Action') subfunction = ran.get('AuditSubFunction') region = ran.get('AuditRegion') Qstans = str(qid)+'|'+ answer+'&&' cursor = connection.cursor() cursor.execute('EXEC [dbo].[sp_SaveAuditResponse] @auditorid=%s,@agents=%s,@supervisor=%s,@ticketid=%s,@Qstans=%s,@sid=%s,@TicketType=%s,@TypeSelected=%s, @Comments =%s, @action=%s, @subfunction=%s, @region=%s', (auditorid,agents,supervisor,ticketid, Qstans,sid, TicketType, TypeSelected, Comments, action, subfunction,region)) result_st = cursor.fetchall() for row in result_st: return Response({0:row[0]}) -
AttributeError: 'Manager' object has no attribute 'filters'
When running Student.objects.filters(years_in_school=FRESHMANN), I get following Error Message: AttributeError: 'Manager' object has no attribute 'filters' class Student(models.Model): FRESHMAN = 'FR' SOPHOMORE = 'SO' JUNIOR = 'JR' SENIOR = 'SR' GRADUATE = 'GR' YEAR_IN_SCHOOL_CHOICES = [ (FRESHMAN, 'Freshman'), (SOPHOMORE, 'Sophomore'), (JUNIOR, 'Junior'), (SENIOR, 'Senior'), (GRADUATE, 'Graduate'), ] year_in_school = models.CharField( max_length=2, choices=YEAR_IN_SCHOOL_CHOICES, default=FRESHMAN, ) # Returns True, if the Objects "year_in_school" equals JUNIOR or SENIOR. def is_upperclass(self): return self.year_in_school in {self.JUNIOR, self.SENIOR} I done makemigrations and migrate already. I have created two objects of Class Student: running Student.objects.all() return me: <QuerySet [<Student: Student object (1)>, <Student: Student object (2)>]>. In Django Admin I created the mentioned objects, one has its property "year_in_school" assigned to "FRESHMAN". Unable to filter the objects by "year_in_school". Why and whats the fix? -
Content-Disposition "inline" --> filename ignored?
I create a HTTPResponse like this (Django): response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'inline; filename="foo.pdf"' response.write(response_data) return response Why does the browser ignore the filename "foo.pdf"?