Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Save data into Model and get data from Model
Hi I'm building a Webshop with a cart and checkout function. Now I'm trying to save the cart data in a Django Model so I can retrieve it. Now my question is how could I do that? and how can I get the data from an model? Here are my models: This is the model I want to save the data in: class MessageItem(models.Model): customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True) mItem = models.CharField(max_length=255, null=True) mQuantity = models.CharField(max_length=255, null=True) # Could also be an Integer! mOrderItem = models.CharField(max_length=255, null=True) Here are my other models: class Customer(models.Model): user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE) name = models.CharField(max_length=200, null=True) email = models.CharField(max_length=200) class Product(models.Model): name = models.CharField(max_length=200, null=True) price = models.FloatField() digital = models.BooleanField(default=False, null=True, blank=False) # Nicht nötig image = models.ImageField(null=True, blank=True) class Order(models.Model): customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True) date_ordered = models.DateTimeField(auto_now_add=True) complete = models.BooleanField(default=False, null=True, blank=False) transaction_id = models.CharField(max_length=200, null=True) class OrderItem(models.Model): product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True) order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True) quantity = models.IntegerField(default=0, null=True, blank=True) date_added = models.DateTimeField(auto_now_add=True) Here is my View: I Want to save: item.product.name, item.quantity and items into the model. @login_required(login_url='login') def cart(request): # If user logged in or not (Handling orders in cart) if request.user.is_authenticated: … -
Display posts made by a user one by one in django
I am making this simple blog site in django. My friend working on the frontend made a user profile page which shows all the posts made by the user. My problem is that I know how to render out all the posts using {% for bl in blog %} but this lists down all the posts made by the user together but the user profile page is such that it creates these small boxes in which I wish to show only one post title and a read more to open the post but I am not able to show single posts. I want other posts to be in their respecitve boxes. Is there any way to show single posts without using the for loop. Here is the views.py num_post = BlogPost.objects.filter(author=request.user.id).count() blogs = BlogPost.objects.filter(author=request.user.id).order_by('-time') return render(request, "user_blog.html", {'blog': blogs, 'user':user }) Here is the model: author = models.ForeignKey(User, default=None, on_delete=models.CASCADE) title = models.CharField(max_length=30) editor = RichTextField() topic = models.CharField(max_length=25) time = models.DateField(default=now) Here is the block in html where I am trying to show the data. <div class="card2"> <img src="{% static 'images/2.jpg' %}" alt="Avatar" style="width:100%"> <div class="container"> <h4>Blog author: {{ blog.author }}</h4> <h4><b>Blog Heading: {{ blog.title }}</b></h4> <p>Some intro of … -
Django Microsoft AD Authentication
I noticed that this question was repeated few times, but still, from all the resources, I couldn't manage to make it work properly. I'm simply trying to use Azure Active Directory authentication with my Django app. I am using this module, and I configured everything as noted in the docs. The thing is - I can't figure out where should user enter the credentials - since the module has only one url ('auth-callback/'). I can't find out how to jump to Microsoft login html page. Should I use my login.html or? Also, I guess that 'auth-callback/' url is obviously a callback URL, which comes after the login page. In terms of Redirect URI's I configured redirect URI to match directly the 'http://localhost:8000/microsoft/auth-callback/' url, which is also how it needs to be I guess. Main problem is - where can I enter the credentials for login? :) Also, when I try this - I get invalid credentials error on my Admin login page : Start site and go to /admin and logout if you are logged in. Login as Microsoft/Office 365/Xbox Live user. It will fail. This will automatically create your new user. Login as a Password user with access to … -
www.name.co and name.co redirects to different pages. Using Django, Heroku, and got the domain from GoDaddy
sorry if I'm writing this in a wrong way but this is my first time writing on stackoveflow. I am building a website on django/heroku and I bought the domain from godaddy. Works perfectly locally and works perfectly on www.name.co, but it takes me to the godaddy 'This Web page is parked FREE, courtesy of GoDaddy.' when i go to name.co Can be seen on the screenshot provided here. https://i.stack.imgur.com/oI05H.jpg I've added www.name.co, *.name.co, and name.co on the domains panel on heroku And I've put the DNS Target of *.name.co on GoDaddy's CNAME. Allowed hosts on my settings.py are like this ALLOWED_HOSTS = ['star (can't put it here for somer eason','name.herokuapp.com','127.0.0.1','0.0.0.0', '*.name.co', 'www.name.co','name.co'] Am I doing something wrong? -
Jquery paginator
I have a table and a jquery paginator linked to it. How can I add a second table with a separate paginator linked to it? I tried using different class names but that didn't work. I highly appreciate any assistance scripts: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/jquery.jold.paginator/jquery.jold.paginator.min.js"></script> html table: <div class="card-body"> <div class="items-container"> {% for key, value in bing.iterrows %} <div class="item item-visible"><a href="{{bing.link}}" target="_blank"> <small class="text-muted">source/{{ bing.source }} : </small>{{ bing.title }} </a></div> {% endfor %} </div> </div> <ul class="pagination-container" ></ul> plugin script: (function($){ var paginator = new $('.items-container').joldPaginator({ 'perPage': 4, 'items': '.item', 'paginator': '.pagination-container', 'indicator': { 'selector': '.pagination-indicator', 'text': 'Showing items {start}-{end} of {total}', } }); })(jQuery); -
How can i make a GET request and return a response to iframe using Django
I have created already a HTML form <form action = "defaut" method = "GET"> Number: <input type="text" name="number" id="number" value=""> Input: <input type="text" name="input" id="input"> newRequest: <input type="text" name="date" id="date" value="0 or 1"> <input type="submit" value="Go" name="go" id="go"> </form> # Views.py def home(request): return render(request, 'myproject/home.html') def defaut(request): message = int(request.GET["input"]) msisdn = int(request.GET["number"]) msc = millis newRequest = int(request.GET["date"]) payloads = dict(input=input, number=number, newRequest=newRequest) res = requests.get("xxxxxx?", params=payloads) print(res.url) return HttpResponse('<h2>asdafasafas </h2>') # from url.py from django.contrib import admin from django.urls import path from qaprojects import views from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('home.html', views.home), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) my issue is that i am getting: sing the URLconf defined in localtool.urls, Django tried these URL patterns, in this order: home.html ^static/(?P.*)$ The current path, default, didn't match any of these. -
TranslatablePage matching query does not exist wagtail custom menu issue
when i am creating wagatil menu translatable page does not exist error display {% load wagtailimages_tags cms_tags %} {% get_menu "main" None request.user.is_authenticated as navigation %} <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav ml-auto mr-5"> {% for item in navigation %} {% get_menu item.slug item.page request.user.is_authenticated as submenu %} <li class="{% if submenu %}dropdown {% endif %}p-2"> <div class="dropdown show"> <a href="{{ item.url }}" {% if submenu %} class="menuitem dropdown-toggle {% if item.icon %}menuicon{% endif %}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" {% else %} data-toggle="tooltip" title="{{ item.title }}" class="menuitem" {% endif %} > {% if item.icon %} {% image item.icon fill-30x30 class="image-menu" %} {% else %} {{ item.title }} {% endif %} </a> {% if submenu %} <div class="dropdown-menu"> {% for subitem in submenu %} <a href="{{ subitem.url }}" class="dropdown-item menuitem p-2 {% if subitem.icon %}menuicon{% endif %}"> {% if subitem.icon %} {% image subitem.icon fill-30x30 class="image-menu" %} {% else %} {{ subitem.title }} {% endif %} </a> {% endfor %} </div> {% endif %} </div> </li> {% endfor %} </ul> </div> -
ERROR H10 App crashed on HEROKU (Django application)
Pls Can someone guide me to solve this error, I want to host my application on Heroku but I'm getting this error. I'm new to this field. I'm getting this error. 2021-02-04T01:05:38.874590+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=grouppublishingindiastore.herokuapp.com request_id=8c528157-dd3c-498a-a86b-a5aabe7796ed fwd="103.252.25.21" dyno= connect= service= status=503 bytes= protocol=https 2021-02-04T01:05:39.670246+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=grouppublishingindiastore.herokuapp.com request_id=3a0b8aa0-94cf-443b-b6b5-a7fab4140f81 fwd="103.252.25.21" dyno= connect= service= status=503 bytes= protocol=https This is my Procfile: web: gunicorn grouppublishingindia:Inventory -
Mocking a function that behaves as if exception never occurred
I am have django view that calls the function on post request, and that function internally calls an other external API, which required to keys to connect. In case of failure that exception occur. What I want is to behave this method behave as if everything is fine, and no exception occurred. But I am not able to do so. What I have tried so far: This is my view @action(detail=False, methods=["POST"]) def unsubscribe(self, request, *args, **kwargs): subscription_id = request.data.get('email') if subscription.email: remove_email_from_list(subscription.email) return Response("Success") this is my remove_email_from_list remove_email_from_list(email): result = exteral_api(email) if result != "1": raise SendyError(result) My test: @mock.patch('core.utils.sendy.remove_email_from_list') @mock.patch('core.utils.simple_texting.remove_phone_from_list') @mock.patch('requests.post',"API.external_api") def test_unsubscribe(self, mock_remove_email, mock_remove_phone, mock_post, mock_external_api): mock_external_api.side_effect = None mock_remove_email.return_value = mock.MagicMock() mock_remove_phone.return_value = mock.MagicMock() mock_post.return_value = mock.MagicMock() self.login_admin() url = reverse('v2-subscription-list') url = f"{url}unsubscribe/" response = self.client.post(url, data={'email': "randomperson@internet.com"}) self.assertOK(response) self.assertEqual(Subscription.objects.all().count(), 0) When I do this it actually access the internet and try the API, but when that API fails I get this error sendy.exceptions.SendyError: <MagicMock name='unsubscribe()' id='140427579614256'> . How can I pass as if exception never occurred? -
how to check perform field validation in resource.py?
I am uploading a .xls file and need to check the below condition before it saves to the model/database. requirement: 1.how to count the total no of rows and compare it with some value and if len(row)<=count(any variable). 2. how to reset count variable in 1 day. resource.py class CTSResource(resources.ModelResource): class meta: Model=CTA def before_import(self, dataset, using_transactions, dry_run, **kwargs): --Logic code--- --Logic code--- I am trying to implement it at the file processing level in my views.py file as shown below. def CTA_upload(request): try: if request.method == 'POST': movie_resource = CTAResource() ##we will get data in movie_resources#### dataset = Dataset() new_movie = request.FILES['file'] if not new_movie.name.endswith('xls'): messages.info(request, 'Sorry Wrong File Format.Please Upload valid format') return render(request, 'apple/uploadinfosys.html') messages.info(request, 'Uploading Data Line by Line...') imported_data = dataset.load(new_movie.read(), format='xls') count = 1 for data in imported_data: value = CTA( data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], ) count = count + 1 value.save() # messages.info(request, count) # time.sleep(1) messages.info(request, 'File Uploaded Successfully...') except: messages.info(request,'Same Email ID has been observed more than once.Except that other records has been added../nPlease Make sure Email field should be unique.') return render(request,'app/cta.html') -
SyntaxError: EOL while scanning string literal (I am trying to connect Django with PostgreSQL)
I am trying to connect Django to the PostgreSQL database, but this is my first time doing it, so I am not sure how exactly to do it. The problem seems to be with the line, where the password is. settings.py - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': '<db_name>', 'USER': '<db_username>', 'PASSWORD: '<password>', 'HOST': 'db_hostname_or_ip>', 'PORT': 'db_port', } } When I try to make migrations in my prompt, (python manage.py makemigrations) I am getting the error mentioned in the title. Can anybody help me please? -
Triggering action on adding object from admin panel
I have a model that holds emails of users who signed up for emails that notify about new articles on the site. Articles are added from the admin panel. I want to figure out how to trigger some function on object addition by admin. MailingList model class MailingList(models.Model): email = models.CharField(max_length=50) def __str__(self): return 'email: ' + str(self.email) Thank you! -
how to use !st image from a list and all the other image separately in different for loop
Hellow everyone, In the first snippet of html, I want to show fist image and in the next loop I want to iterate from 2nd image, {% for p in photos %} {% if forloop.first %} //showing the 1st image <div class="box active" onclick="changeImage(this)"> <img src="{{p.images.url}}"> </div> {% endif %} {% endfor %} {% for p in photos %} {% if forloop.counter %} //showing from 2nd image <div class="box" onclick="changeImage(this)"> <img src="{{p.images.url}}"> </div> {% endif %} {% endfor %} Now in the 2nd snippet of html I used the first image property and then from 2nd image property {% for p in photos %} {% if forloop.first %}//for using first image property <a href="{{p.images.url}}" data-fancybox="gallery1"> <img src="{{p.images.url}}" data-name="show{{forloop.counter0}}" class="hide-image show-image" alt="big_image"> </a> {% endif %} {% endfor %} {% for p in photos %} {% if forloop.counter %}//for using 2nd image property <a href="{{p.images.url}}" data-fancybox="gallery1"> <img src="{{p.images.url}}" data-name="show{{ forloop.counter }}" class="hide-image" alt="big_image"> </a> {% endif %} {% endfor %} But my tmeplate is not working correctly,clicking on the image //onclick function is not working I am unable to find the solution,can any one please suggest me where is the problem,I tested all other parts of the html code individually and … -
Django - Include UpdateView in modal of Templateview
I have built an app that allow user to create a report about clients. Inside that app, to dsplay all the report, I have a page called report_validated.html, which is rendered by a TemplateView (by the way, should I use a ListView instead?) I allow the users to edit their report with an UpdateView that is rendered in report_update.html. So far, everything works good like this. However now, I'd like to allow the user to click on an Edit button that load a modal which will render the update form filled by the already exisiting data from the database. I have been trying to do this and I have been checking multiple posts on this website to find a solution but I have been unable to achieve it. models.py class Report(models.Model): input_title = models.CharField(max_length=200) content = models.TextField() refs = models.CharField(max_length=20) comment = models.TextField() is_noticed = models.BooleanField(default='False') tags = TaggableManager() date_of_writing = models.DateField(default=datetime.date.today) created_by = models.ForeignKey(User, related_name="report", blank=True, null=True, on_delete=models.CASCADE) views.py class ReportValidated(TemplateView): template_name = "taskflow/report_validated.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) today = datetime.date.today() context['preceding_validated_report'] = Report.objects.filter(is_noticed=True).exclude(date_of_writing=today).order_by('-id') context['validated_report_of_today'] = Report.objects.filter(date_of_writing=today).order_by('-id') return context class ReportCreate(LoginRequiredMixin, CreateView): model = Report template_name = 'taskflow/report_create.html' form_class = ReportForm success_url = None def form_valid(self, form): … -
Is it possible to make email confirmation key shorter with dj-rest-auth?
I am making a rest api for mobile application. I am using dj-rest-auth package for the overall authentication process. Overall auth functionality works fine but One thing I want to modify is to make the email confirmation key shorter. User will get email like this. Please use this key to confirm your email. MjE:1l7ZhR:f6U2RWlx2kEJY2jXzFuAuKpKclNyc3MpaKmeiEFGp3Y In my email verify api user need to enter this whole key for verification. Is there any way to make this key shorter so that it will be good from user perspective(I think) ? I have made my custom adapter here. class MyAdapter(DefaultAccountAdapter): def send_confirmation_mail(self, request, emailconfirmation, signup): current_site = get_current_site(request) activate_url = self.get_email_confirmation_url( request, emailconfirmation) ctx = { "user": emailconfirmation.email_address.user, "activate_url": activate_url, "current_site": current_site, "key": emailconfirmation.key, } -
Saving data from Views to Database
Hi I'm building a Webshop with a cart and checkout function. Now I'm trying to save the cart data in a Django Model so I can retrieve it. Now my question is how could I do that? and how can I get the data from an model? Here are my models: This is the model I want to save the data in: class MessageItem(models.Model): customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True) mItem = models.CharField(max_length=255, null=True) mQuantity = models.CharField(max_length=255, null=True) # Could also be an Integer! mOrderItem = models.CharField(max_length=255, null=True) Here are my other models: class Customer(models.Model): user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE) name = models.CharField(max_length=200, null=True) email = models.CharField(max_length=200) def __str__(self): return self.name class Product(models.Model): name = models.CharField(max_length=200, null=True) price = models.FloatField() digital = models.BooleanField(default=False, null=True, blank=False) # Nicht nötig image = models.ImageField(null=True, blank=True) def __str__(self): return self.name @property def imageURL(self): try: url = self.image.url except: url = '' return url class Order(models.Model): customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True) date_ordered = models.DateTimeField(auto_now_add=True) complete = models.BooleanField(default=False, null=True, blank=False) transaction_id = models.CharField(max_length=200, null=True) def __str__(self): return str(self.id) @property def get_cart_total(self): orderitems = self.orderitem_set.all() total = sum([item.get_total for item in orderitems]) return total @property def get_cart_items(self): orderitems = self.orderitem_set.all() total = sum([item.quantity for item … -
Django Oauth Toolkit: User data over introspection
Current Scenario: I'm using Introspect to validate access token on the authentication server. This call returns only 'username' of the user from the authentication server and saves it in the resource server. The Id of the same user on the authentication server and the resource server are no necessarily the same. Desired Scenario: I want to receive more data about the user (email, phone number, address, etc..) and save it in the resource server. What I have done so far: I modified the django-oauth-toolkit/oauth2_provider/views/introspect.py/ get_token_response to return the data I need. What is remaining: How do I save those data in the resource server? or is it better to make an api call to the authentication server whenever I require the user data? -
How to change the "timestamp without time zone" to "timestamp with time zone" using Django models using migrations?
class test(models.Model): mobile_last_login = models.DateTimeField() I need to change the "timestamp without time zone" to "timestamp with time zone" for the "mobile_last_login" field. -
Celery sending tasks as a group
So I have some tasks in celery that are not registered in the current process and what I am trying to achieve is to actually make a group call for multiple tasks. For example: from celery import group, Signature, signature from task_app import celery_app from celery.execute import send_task workflow = group([ send_task( 'my_task.deploy', kwargs={ 'name': 'dev1', 'site': 'somesite', 'sleep': 1 }, immutable=True, app=celery_app, )] ) result = workflow() print(result.get()) The problem is that using send_task is group will give me this error Traceback (most recent call last): File "workflows.py", line 17, in <module> result = workflow() File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/canvas.py", line 1077, in __call__ return self.apply_async(partial_args, **options) File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/canvas.py", line 1102, in apply_async results = list(self._apply_tasks(tasks, producer, app, p, File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/canvas.py", line 1182, in _apply_tasks for sig, res in tasks: File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/canvas.py", line 1163, in _prepared task = from_dict(task, app=app) File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/canvas.py", line 139, in from_dict typ = d.get('subtask_type') File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/result.py", line 223, in get return self.backend.wait_for_pending( File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/backends/asynchronous.py", line 199, in wait_for_pending for _ in self._wait_for_pending(result, **kwargs): File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/backends/asynchronous.py", line 265, in _wait_for_pending for _ in self.drain_events_until( File "/home/vladnedelcu/Desktop/asyncStuff/env/lib/python3.8/site-packages/celery/backends/asynchronous.py", line 51, in drain_events_until if timeout and time.monotonic() - time_start >= timeout: TypeError: '>=' not supported between instances of 'float' and 'str' … -
how to retrieve an object with generic relation (ContentType) in Django
I used ContentType in my django 3.1 project to implement a wishlist. here is my models.py: # Users.models.py class WishListItem(models.Model): owner = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=50, null=True, blank=True) count = models.IntegerField(null=True, blank=True) price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') I declard the genericRelation in other models ( that are from other apps). for example: another_app.models.py: # Support.models.py class Training_Lists(models.Model): title = models.CharField(max_length=50, unique=True) cover = models.ImageField(upload_to='photos/support/tranings/', null=True, blank=True) is_published = models.BooleanField(default=True) slug = models.SlugField(null=False, unique=True) price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) tags = GenericRelation(WishListItem, related_query_name='training', null=True, blank=True) In my scenario, I want to retrieve a training object in order to get it's price. based on Django docs for ContentType.get_object_for_this_type(**kwargs), I should retireve the model type which I am looking for, then get the object with get_object_for_this_type. in the docs, it says: from django.contrib.contenttypes.models import ContentType user_type = ContentType.objects.get(app_label='auth', model='user') # <= here is my question user_type <ContentType: user> user_type.get_object_for_this_type(username='Guido') <User: Guido> here is my question: what are app_lable and model parameters? in Users.views.py I want to retrieve the price of an Training_Lists object which is added to wishlist as a WishListItem object. -
how to get the device registration_id
registration_id = "<device registration_id>" message_title = "Uber update" message_body = "Hi john, your customized news for today is ready" result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body) i have 2 django apps and I want to send notification from one website to another . for this I am using pyFCM but I am not able to get the device registration_id for another device and how to use it . pyFCM -
How to Override config model in djago-constance backend.database.model in a django app
i have used django-constance package in my project. I want to add some fields the config model. Where should i write the code to override config model -
NGINX does not serve the collected static files
I am running a dockerized Django application on an AWS EC2 instance, and the page loads without the static files, even though NGINX has them collected. I find this pretty strange, as it had not happened to me until now (at least on my local machine). It would be greatly appreciated if you could help me solve this issue. This is my docker-compose.yml file: version: "3" services: web: restart: always build: . command: bash -c " python manage.py makemigrations && python manage.py migrate && python manage.py creategroups && python manage.py initializesuperuser && python manage.py collectstatic --noinput && daphne -b 0.0.0.0 -p 80 DL.asgi:application" expose: - 80 environment: - DJANGO_SETTINGS_MODULE=DL.production_settings volumes: - static_volume:/usr/src/app/DL/static/ - media_volume:/usr/src/app/media_cdn nginx: restart: always build: ./nginx ports: - "80:80" volumes: - static_volume:/static/ - media_volume:/media/ depends_on: - web volumes: static_volume: media_volume: Here's production_settings.py: STATIC_URL = '/static/' STATIC_ROOT = "/usr/src/app/DL/static/" A snippet of the file structure inside the web container (DL_app is the name of the Django app): usr | |──src | |──app | |──DL | |──DL | |──DL_app | | | |──static | |──manage.py | |──static And, lastly, here's nginx.conf: upstream web { server web:80; } server { listen 80; location / { proxy_pass http://web; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; … -
C:\Users\bhanu\AppData\Local\Microsoft\WindowsApps\python.exe: can't open file
C:\Users\bhanu\AppData\Local\Microsoft\WindowsApps\python.exe: can't open file 'C:\Users\bhanu\Desktop\Python Course with Notes\django\blog\manage.py': [Errno 2] No such file or directory This error occur when I am try to runserver in django . using python manage.py runserver -
Overriding templates with same name is django
I have a app named company in django, while both the template directories i.e one in company/templates and the other in base_dir/templates have a file named index.html. when i try to render the templates index.html from company app it renders the template from base directory. I want to override this so that every app uses it's own template directory for rendering. Is there any way by which I can make this possible. I have added all template directories in settings.py Thanks in advance