Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
SMTP mail getting bounced using Heroku, Django and Outlook (goDaddy)
So I'm having some issues with sending emails using SMTP with Django, Heroku and a GoDaddy (office 365) email. My email setup is as such: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.office365.com' EMAIL_HOST_USER = HOSTUSER EMAIL_HOST_PASSWORD = LOCALPASSWORD EMAIL_PORT = 587 EMAIL_USE_TLS = True If I send a standard test e-mail LOCALLY (i.e. by running my app locally) like this: import django django.setup() from django.conf import settings from django.core.mail import send_mail send_mail( subject = 'That’s your subject', message = 'That’s your message body', from_email = settings.EMAIL_HOST_USER, recipient_list = [some_email_address,], fail_silently = False ) It works just fine. Also, I am able to send e-mails as normal through my Outlook webmail. However, when I launch this app to Heroku and try to send a test e-mail, I get a bounce-back to my webmail that looks like this: Remote Server returned '550 5.7.708 Service unavailable. Access denied, traffic not accepted from this IP. For more information please go to http://go.microsoft.com/fwlink/?LinkId=526653 AS(8561) [CWXP265MB3078.GBRP265.PROD.OUTLOOK.COM]' Received: from CWLP265MB3922.GBRP265.PROD.OUTLOOK.COM ([fe80::f472:c360:b020:723b]) by CWLP265MB3922.GBRP265.PROD.OUTLOOK.COM ([fe80::f472:c360:b020:723b%6]) with mapi id 15.20.4308.022; Thu, 8 Jul 2021 16:29:32 +0000 MIME-Version: 1.0 Content-Type: text/plain Date: Thu, 8 Jul 2021 16:29:32 +0000 Message-ID: 162576177199.10.1317079512283763999@7b074c75-3c7b-4c2c-9dc4-caf0ce6cbd26.prvt.dyno.rt.heroku.com So it seems to me that the IP address assigned to … -
PasswordResetForm special usage HTML email template not rendering
my email template (see code below) does not render. You can imagine that reset_password_after_slack_registration is allowing me on pressing a button to send an user a email to reset his password with another message than the standard password reset message (see below). But it is not rendering and e.g. the are still showing up. Any ideas on how to fix? Thanks!! from django.contrib.auth.forms import PasswordResetForm def reset_password_after_slack_registration(email, from_email, template='users/slack_account_password_reset_email.html'): """ Reset the password for an user """ form = PasswordResetForm({'email': email}) form.is_valid() return form.save(from_email=from_email, email_template_name=template) The template looks like this: {% autoescape off %} Hi {{ user.first_name }}, <br> <br> You have requested to set an account for your XYZ account that you have been using via Slack so far.<br> For your XYZ account {{ user.email }}, you can <a href="https://example.com/accounts/google/login/">Sign in with Google</a> or set a a password, by clicking the link below:<br> https://example.com{% url 'slack_account_password_reset_confirm' uidb64=uid token=token %} <br><br> If clicking the link above doesn't work, please copy and paste the URL in a new browser window instead. <br><br> All the best,<br> Your XYZ team {% endautoescape %} And the URLs look like this: # Slack Accounts path('slack/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name='users/slack_account_password_reset_confirm.html'), name='slack_account_password_reset_confirm'), -
How to retrieve an image from static folder using javascript and django
I have trouble trying to get an image from static folder. When I pass the image in the html it works. here is my code <div id="dirs" class="card mb-3" style="max-width: 540px;"> <div class="row no-gutters"> <div class="col-md-4"> <img src="{% static 'PERDNI/09401576.jpg' %}" class="card-img" alt="..."/> </div> <div class="col-md-8"> <div class="card-body"> <h5 class="card-title">Datos personales</h5> <p class="card-text">This is a wider card.</p> </div> </div> </div> </div> This is the generated html in the browser inspector: In other hand, when I generate the html from a javascript file, it doesn't work, The image doesn't appear but the other part of the html yes. Here is my code var datahtml='<div class="row no-gutters"><div class="col-md-4">'; datahtml+='<img src="{% static ' datahtml+="'PERDNI/09401576.jpg'" datahtml+=' %}" class="card-img" alt="My image"/>' datahtml+='</div><div class="col-md-8"><div class="card-body">' datahtml+='<h5 class="card-title">Card title</h5>' datahtml+='<p class="card-text">Hello</p>' datahtml+='</div></div></div>' document.getElementById("dirs").innerHTML=datahtml This is the other generated html in the browser inspector: What would be the problem, I was thinking in the quotes however I tried in many ways and It haven't worked yet. Thanks in advance. -
Django-ckeditor Error code: exportpdf-no-token-url
I try to add ckeditor 6.1 to my form allow user to post an article. I followed a video on youtube to install and setting, I successfully add a new post using ckeditor in django admin page. But in html page, the richtext field shows but with below error. When I just render the page with GET method (have not submit the form yet), in console I always get the error : ckeditor.js:21 [CKEDITOR] Error code: exportpdf-no-token-url. and Submit also doen't work. I am new with django, this is a final shool project. I don't need to export to PDF, how can I just disable? or any idea, please help, I have stuck here for a few days. class Article(models.Model): user = models.ForeignKey("User", on_delete=models.CASCADE, related_name='post_user') title = models.CharField(max_length=150) body = RichTextUploadingField(blank=True, null=True) class Post_Form(ModelForm): class Meta: model = Article exclude = ['user'] widgets = { 'title': TextInput(attrs={'class': 'form-control', 'id': 'title' }), 'body': Textarea(attrs={'rows':10, 'cols':40}), } views.py def write_post(request): form = Post_Form(request.POST) return render(request, 'write_post.html', { 'form': form, }) setting.py CKEDITOR_CONFIGS = { 'default': { 'height': 800, 'width': 1000, }, } CKEDITOR_UPLOAD_PATH = "uploads/" html <form action="" method="POST" enctype="multipart/form-data"> {% csrf_token %} {{ form.media }} {{ form.as_p }} <div type=submit class="btn … -
Using F() expression in Django update method
I have a Django model called Tree representing tree objects and it contains x and y coordinate fields of type FloatField. I am trying to call Django's update method to initialize a PointField called coordinates for each tree object with the following command: Tree.objects.all().update(coordinates=Point(F('x'), F('y'))) If I understood correctly from the documentation, I would need to use the F() expression to access the fields of each tree object at the database level. However, this does not work and results in the following error: Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options) File "/usr/src/app/app/tree_api/management/commands/update_coords.py", line 47, in handle Tree.objects.all().update(coordinates=Point(F('x'), F('y'))) File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/geos/point.py", line 35, in __init__ raise TypeError('Invalid parameters given for Point initialization.') TypeError: Invalid parameters given for Point initialization. What I'm trying to achieve could be done using the following raw SQL query: UPDATE tree_column_name SET coordinates = ST_GeomFromText('POINT(' || x || ' ' || y || ')'); Is it possible to initalize the PointField from x … -
referencing Django changing static images paths
I have a line of code <img src="{% static 'mysite/plots/' %}{{ plot }}" alt="Stock price vs. predictions graph" style="width: 600px; height: 450px;"> where I want to display images based on a variable called plot that I pass from my views.py. For example, this variable could be 'AAPL.PNG' or 'TSLA.PNG', whatever the image name is, I am sure that I have it stored at my static/mysite/plots/ directory because when I access these paths directly with {% static 'mysite/plots/AAPL.PNG' %} it works. I have also tried: src="{% static 'mysite/plots/{{ plot }}' %}" src="{% static 'mysite/plots/'(plot) %}" src="{% static 'mysite/plots/' + plot %}" -
django-rest-framwork Got AttributeError when attempting to update a value
There is an error "Got AttributeError when attempting to get a value for field learner on serializer LearnerAddressSerializer.\nThe serializer field might be named incorrectly and not match any attribute or key on the Learner instance.\nOriginal exception text was: 'Learner' object has no attribute 'learner'." I don't know how to solve this error. models.py class LearnerAddress(Address): learner = models.ForeignKey('learner.Learner', on_delete=models.CASCADE, related_name="learner_address") views.py def patch(self, request, learner_id): ......... ......... if key == 'address_details': address_serializer = LearnerAddressSerializer(instance=instance, data=value, partial=True) address_serializer.is_valid(raise_exception=True) address_serializer.save() response_data['address'] = address_serializer.data serializer.py class LearnerAddressSerializer(serializers.ModelSerializer): class Meta: model = LearnerAddress fields = '__all__' The above error occurs when I try to update data, also tried many=True. I am a beginner in Django, so I also need a little bit of description , expecting immediate help also. json input: "address_details": { "name":"name" } -
Why will my django model data not display in html
Following this tutorial, I am creating a simple ecommerce website. I have data stored in a Django model, and I am calling it in my view, but it will not display in my html. Basically, I want it to create one of the boxes bellow for every donation in the donation model, but it will not work. Can someone please help me? I know this seems like an easy fix, I just can't wrap my head around it. My code is down bellow. View: def availablesupplies(request): donations = Donation.objects.all() context = {'donations':donations} return render(request, 'availablesupplies.html') Model: class Donation(models.Model): title = models.CharField(max_length=30) phonenumber = models.CharField(max_length=12) category = models.CharField(max_length=20) quantity = models.IntegerField(blank=True, null=True,) location = models.CharField(max_length=50, blank=True, null=True,) description = models.TextField() datedonated = models.DateTimeField(auto_now_add=True) user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True, ) HTML: <div class="row"> {% for donation in donations %} <div class="col-lg-4"> <img class="thumbnail" src="{% static 'images/gooddeedplaceholderimage.png' %}"> <div class="box-element product"> <h6><strong>Product</strong></h6> <hr> <button class="btn btn-outline-secondary add-btn">Add to Cart</button> <a class="btn btn-outline-success" href="#">View</a> <h4 style="display: inline-block; float: right"><strong>$20</strong></h4> </div> </div> {% endfor %} </div> {% endblock content %} -
git: 'remote-https' is not a git command. See 'git --help'
I have been trying to clone my repository and it shows the following error:- git: 'remote-https' is not a git command. See 'git --help' Here is my:- Clone from https://github.com/NavyaThakur/django-project1 To directory C:\Users\91933\github\django-project1 I tried reinstalling github desktop but no use. Please help me through this -
Push failed to Heroku - Python Django
I was trying to deploy my django app on heroku, I did not create a virtual environment, and this is my first time doing it. When I tried to push to heroku I got error after installing all packages -: -----> $ python manage.py collectstatic --noinput Traceback (most recent call last): File "/tmp/build_b0d1f9a6/manage.py", line 22, in <module> main() File "/tmp/build_b0d1f9a6/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options) File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle collected = self.collect() File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect handler(path, prefixed_path, storage) File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 338, in copy_file if not self.delete_file(path, prefixed_path, source_storage): File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 248, in delete_file if self.storage.exists(prefixed_path): File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 318, in exists return os.path.exists(self.path(name)) File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 38, in path raise ImproperlyConfigured("You're using the staticfiles app " django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. ! Error while running '$ python manage.py collectstatic --noinput'. See traceback above for details. You may need to update application code to resolve this error. Or, you can disable … -
Django administration error after changing the model
good morning, I have a problem with a django app deployed as a web app on Microsoft Azure. Basically after adding an imageField to a model, when from administration I enter in the modification of one of those objects (related to that model) I get the following error: No module named 'backend' Request Method: GET Request URL: http://......myurl...../adminforsuperuser/auth/tenants/tenant/4791c751-bc04-4bb5-aa9f-82732b7c3217/change/ Django Version: 2.2.8 Exception Type: ModuleNotFoundError Exception Value: No module named 'backend' Exception Location: in _find_and_load_unlocked, line 953 Python Executable: /opt/python/3.6.12/bin/python3.6 Python Version: 3.6.12 Python Path: ['/opt/python/3.6.12/bin', '/tmp/8d942cfe6a508ea', '/tmp/8d942cfe6a508ea/antenv3.6/lib/python3.6/site-packages', '/opt/python/3.6.12/lib/python36.zip', '/opt/python/3.6.12/lib/python3.6', '/opt/python/3.6.12/lib/python3.6/lib-dynload', '/opt/python/3.6.12/lib/python3.6/site-packages'] Server time: Fri, 9 Jul 2021 12:04:19 +0000 More details about the error: image The field I add to the model: logo= models.ImageField(upload_to=path_and_rename, default='tenant_logos/default_logo.png') Practically the fact that in edit must also show me the form to change the image (and the path of the image currently saved in that object) breaks the whole page. The strange thing is that it works locally! They, local and prod, have the same apps installed: INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.admin', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'crispy_forms', .....my app here... , ] Thank you! -
facing two problem when I was giving image path on src in JS file then show error, second when I was click on image the click even not fire
I am fetching table heading column name dynamically using Ajax. I want to give icon on first column heading. the problem is, I am giving path src="{% static 'image/upArrow.png'%}" but it's not working on getData.js file, when I am giving same path on home.html then image icon show on html, I define in {% load static %} on Js but still not work. second problem, I click on error image icon then click event not fired, when i gave the static table heading column name then its work properly. I am using django for backend getData.js file where fetching data function execTable(data){ var table_header = document.getElementById('exce-header') var table=document.getElementById('exce-table') console.log("keyyy : ",Object.keys(data[0])) key = Object.keys(data[0]) console.log('valueee : ',data[0][key[0]]) for (let i=0;i<key.length;i++){ var header; if(i==0){ header = ` <th> <img src="{% static 'image/upArrow.png'%}" id="up_Arrow" class="toggle_child" style="visibility: visible" /> ${key[i]} </th> `} else { header = ` <th> ${key[i]} </th> `} table_header.innerHTML+=header } } home.js file where click event wrote. var test_bool= true; $('.toggle_child').on('click', function(event) { test_bool = !test_bool if(test_bool == false){ document.getElementById("c-table-3").style.height ="30px"; } else{ document.getElementById("c-table-3").style.height ="129px"; } }); home.html file where display file data <div class="panel" id="c-table-3"> <div class="table-data" > <table > <thead class="accordion"> <tr id="exce-header"> </tr> </thead> <tbody id="exce-table" > … -
How to pass an HTTP request as a parameter of a python function?
I'm calling a python function and passing an HTTP request as a parameter but it's not working. I created the function in a View and called it in another, but the parameter fails. Here's the function I'm calling def load_colmeias(request): apiario = request.GET.get('apiario') if apiario != "": colmeias = Colmeia.objects.filter(apiario=apiario) return render(request, 'colmeias_choices.html', {'colmeias': colmeias}) else: return render(request, 'colmeias_choices.html') Here I call her load_colmeias(request) But the following error occurs NameError: name 'request' is not defined I already imported the "urlib" and "requests" libraries but it always gives the same error: AttributeError: module has no attribute 'GET' Can someone help me ?? I'm new to Python/Django and I'm still learning how to do things -
How to validate a formset in dajngo
I am using formset to input my data into the database but for some reason it just doesn't validate, whenever I test in the terminal and call the .is_valid() It just returns false no matter what I try. Here's the code in my views.py and forms.py . Any help will be much appreciated! # Advanced Subjects (Advanced Biology) def form_5_entry_biology_view(self, request): current_teacher = User.objects.get(email=request.user.email) logged_school = current_teacher.school_number students_involved = User.objects.get(school_number=logged_school).teacher.all() data = {"student_name": students_involved} formset_data = AdvancedStudents.objects.filter(class_studying="Form V", combination="PCB") student_formset = formset_factory(AdvancedBiologyForm, extra=0) initial = [] for element in formset_data: initial.append({"student_name": element}) formset = student_formset(request.POST or None, initial=initial) print(formset.is_valid()) context = { "students": students_involved, "formset": formset, "class_of_students": "Form V", "subject_name": "Advanced Biology", } return render(request, "analyzer/marks_entry/marks_entry_page.html", context) And here is my forms.py class AdvancedBiologyForm(forms.ModelForm): student_name = forms.CharField() class Meta: model = ResultsALevel fields = ('student_name', 'advanced_biology_1', 'advanced_biology_2', 'advanced_biology_3',) -
how to return queryset by ajax data
I want to make a modal window but I intend to make it shorter, so I'm looking for ajax. When button clicked, POST id parameter to Django by ajax. I made with class=popup-click, id=post.id (post is a query from django model Post) Make a queryset in django by using ajax data. it maybe like 'Post.objects.get(id = (ajax data)). Using this queryset to dispose of a modal window. but I'm not familiar with ajax. so yet the POST method is errored. Help me, bro. -
django: FooSearchListView' object has no attribute 'object_list'
I am using Django 3.2 and django-taggit 1.4 I have a model Foo defined like this: /path/to/myapp/models.py class Foo(models.Model): title = models.CharField() story = models.CharField() caption = models.CharField() tags = TaggableManager() I am trying to write a search for Foo objects matching one or more tags, using CBV. Here is my code: /path/to/myapp/views.py class FooSearchListView(ListView): model = Foo slug_field = 'query' context_object_name = 'foo_list' paginate_by = 3 def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) return context def post(self, request, *args, **kwargs): query_original = request.POST.get('search_terms', None) page = request.POST.get('page', 1) q_filter = Q() if query_original: keywords = [x.strip() for x in query_original.lower().split(',')] title_match = reduce(operator.or_, (Q(title__icontains=word) for word in keywords)) story_match = reduce(operator.or_, (Q(story__icontains=word) for word in keywords)) captions_match = reduce(operator.or_, (Q(caption__icontains=word) for word in keywords)) tags_match = reduce(operator.or_, (Q(tags__name__icontains=word) for word in keywords)) q_filter = title_match | story_match | captions_match | tags_match foos = Foo.objects.filter(q_filter).distinct().order_by('-date_added') context = self.get_context_data(*args, **kwargs) context['keywords'] = keywords return render(request, 'search_items.html', context=context) /path/to/my/app/urls.py urlpatterns = [ # ... path('search/', FooSearchListView.as_view(), name='foo-search'), # ... ] I don't like the way I have structured the code, because I am not able to override methods like get_queryset(), etc. and all of the logic is just in the post() … -
I need to make a slider having 3 images each
I have a list of products an im going to use for loop to get each product details with photo from backend,now i want make a slider using carousel in which each slide will be having 3 images each means three products each and on slding i will next three products.Please answer me with respect to django as i know normal carousel code is available online. -
TypeError: index_queryset() got an unexpected keyword argument 'using'
Django==3.2.5 django-haystack==3.0 pysolr==3.9.0 Solr = 8.9.0 I am following the tutorial as in https://django-haystack.readthedocs.io/en/master/tutorial.html to create an Django application with Solr. While executing ./manage.py rebuild_index, I am getting an error like: **File "/..../tele_env/lib/python3.8/site-packages/haystack/indexes.py", line 202, in build_queryset index_qs = self.index_queryset(using=using) TypeError: index_queryset() got an unexpected keyword argument 'using'** I am stuck up since 3 days solving this error. Tried to downgrade each of the packages (Django, pysolr, haystack with solr 6.6, but didn't help me. Please help me to get out of this circle of upgrading and downgrading... Thanks in advance -
How to save comment while blog post save in Django
Info: I want to save comments form when i submit the form of blog post. problem: if i fill the form of comment then comment save with blog post form other wise comments is blank in database. i don't understand how can perform this logic? **Views.py def PostCreate(request): post_form = PoatForm() comment_form = CommentForm() if request.method == 'POST': post_form = PostForm(request.POST) comment_form = CommentForm(request.POST or None) if post_form.is_valid() or comment_form.is_valid(): post = ticker_form.save(commit=False) post.author = request.use post.save() com = comment_form.save(commit=False) com.post_by = request.user com.post = post com.save() return redirect('/') context = { 'post_form': post_form, 'comment_form': comment_form, } return render(request, "post/create.html", context) -
How to generate a zoom meeting using Django?
I have created a JWT app on zoom marketplace and got API key and secret but i am not able to understand and bit confused like how to create a zoom meeting by making post request to zoom using Django -
Detect database DDL schema changes with Django
Let's say that we have a Django app that looks on a legacy database. If someone make changes on some database tables from a db client as DBeaver for example and not through Django models, is there a way to identify these changes? -
Filtering the table using Date
I am facing an issue with filtering the table data by its created date. I have a Part model where I have created a date field that auto add the creation date and I am using queryset to filter the table. However, I managed to do filtering by Product and Supplier name but in the below code, I also tried to filter by date but somehow it doesn't work. After filtering the table by date, still I can see old data in there. models.py class Part(models.Model): created_date = models.DateField(auto_now_add=True) views.py def get_queryset(self, request): queryset = self.model.objects.all().order_by('-id') if self.request.GET.get('supplier'): queryset = queryset.filter(supplier_id=self.request.GET.get('supplier')) elif self.request.GET.get('product'): queryset = queryset.filter(product_id=self.request.GET.get('product')) elif self.request.GET.get('created_date'): queryset = queryset.filter(created_date=self.request.GET['created_date']) return queryset filters.py class PartFilter(django_filters.FilterSet): class Meta: model = Part fields = ['partno', 'product', 'supplier','created_date'] Can anyone help me out? Thank you very much -
django.db.utils.ProgrammingError: relation does not exist with recursive model
I have a django app that is working as intended on my local pc. but when I'm deploying it to heroku it prints the message: django.db.utils.ProgrammingError: relation "core_menuoption" does not exist Now, I searched about this a lot, but no case is similar as mine. I think that my problem is because my model MenuOption is recuesive. Here is the model: class MenuOption(models.Model): parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True) title = models.CharField(max_length=50, unique=True) ... As you can see, the parameter parent is a foreign key to this model. So I think becuase the model is not yet created, django doesn't know which model to relate to. I thought about maybe deleting this field, migrate and than bring it back, but too many things rely on this field. -
cannot load background images when the source URL is provided in stylesheet instead of HTML code, Using django STATIC_URL
I am unable to load the background image of my webpage when using {static} in my CSS code It's difficult to explain so I will just paste the snippets here: Inside settings.py I have configured STATIC items as follows: ```STATIC_URL = '/static/' STATICFILES_DIRS=[ os.path.join(BASE_DIR,'static') ,] # ] STATIC_ROOT= os.path.join(BASE_DIR, 'assets')``` I have used the command: python manage.py collectstatic to collect all the static items inside the assets folder(in the base directory) images/files, for example "ii.jpg" inside project/static/img whose source provided in the HTML template render fine using this code <div class="imgbox"><img src="{%static 'img/ii.jpg'%}"></div> but then I try to render image using : ```background: linear-gradient(rgba(0,0,0,0.5),#05071a) ,url("{%static 'img/ff_1.jpg'%}") no-repeat center center/cover;``` the browser console gives 404(image not found error) even when the name and extension are correct I will attach the screenshot of the error shown in the browser console. Now, one more thing, when I hover over the {%static 'image_name'%}, I think it shows me the interpreted path as shown in 3rd screenshot I feel like it's looking for img folder in project/static/styles/ instead of project/static/ if that's the error IDK how to fix this please refer the 4th screenshot to see my folder structure(carnival is the app's name,ITAproject is name … -
CS50 Python & JS Web: Cannot operate website after trying to 'makemigrations'
I have been working through the Web with Python and Django with the CS50 course. When i got to the stage of 'makemigrations' it didnt run and not i cant use the command 'runserver' either. PS C:\Users\44777\code\airline> python3 manage.py runserver Watching for file changes with StatReloader Performing system checks... Exception in thread django-main-thread: Traceback (most recent call last): File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 591, in url_patterns iter(patterns) TypeError: 'module' object is not iterable The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Python38\lib\threading.py", line 932, in _bootstrap_inner self.run() File "D:\Python38\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "D:\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "D:\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "D:\Python38\lib\site-packages\django\core\management\base.py", line 392, in check all_issues = checks.run_checks( File "D:\Python38\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config return check_resolver(resolver) File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver return check_method() File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 409, in check messages.extend(check_resolver(pattern)) File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver return check_method() File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 408, in check for pattern in self.url_patterns: File "D:\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e django.core.exceptions.ImproperlyConfigured: The …