Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django showing {% block title %} if {% content.meta_title %}
I need help with displaying django template block. In base.html I have block with default value. <title>{% block title %}Default Title{% endblock %}</title> In page.html I have if statement with a block inside. {% extends 'base.html' %} {% if homeContent.meta_title %} {% block title %}Title for this Page{% endblock %} {% endif %} Currently content.meta_title is None. However, in rendered html the title is shown as: <title>Title for this Page</title> I have tried to have different conditions like != '' or != None. But it still does not work. Please help me to find way around. I am confused. -
Email Verification Fail in Django webapp hosted on Elastic Beanstalk
I was making a web app on Django. I tried to send an email verification link to any new user who registers on my website. The thing works fine when I am hosting it on localhost but upon hosting on AWS Elastic Beanstalk the email verification shows an invalid token. models.py from django.contrib.auth.models import User from django.db import models # Create your models here. from django.utils.safestring import mark_safe class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) phone = models.CharField(blank=True, max_length=20) address = models.CharField(blank=True, max_length=150) city = models.CharField(blank=True, max_length=20) PINcode = models.IntegerField(blank=True, null=True) country = models.CharField(blank=True, max_length=50) image = models.ImageField(blank=True, default="Users/profile.png", upload_to='images/users/') def __str__(self): return self.user.username def user_name(self): return self.user.first_name + ' ' + self.user.last_name + ' [' + self.user.username + '] ' def image_tag(self): return mark_safe('<img src="{}" height="50"/>'.format(self.image.url)) image_tag.short_description = 'Image' forms.py from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.contrib.auth.models import User from django.forms import TextInput, EmailInput, Select, FileInput from user.models import UserProfile class SignUpForm(UserCreationForm): username = forms.CharField(max_length=30,label= 'User Name :') email = forms.EmailField(max_length=200,label= 'Email :') first_name = forms.CharField(max_length=100, help_text='First Name', label= 'First Name :') last_name = forms.CharField(max_length=100, help_text='Last Name', label= 'Last Name :') class Meta: model = User fields = ('username', 'email','first_name','last_name', 'password1', 'password2', ) def __init__(self, *args, … -
Django, enabling html tag in the return value of admin.ModelAdmin class
For example, the code below. I want to use <pre> tag in the django's admin.ModelAdmin class MyJsonDataAdmin(admin.ModelAdmin): list_display = ['show_jsondata'] def show_jsondata(self,obj): temp = json.dumps(obj.jsondata, indent=2) return "<pre>" +temp + "</pre>" Is there any practice??? -
Postgres server does not support SSL, but SSL was required - CircleCI
I'm creating a build-test-deploy pipeline using CircleCI for a Django application. With image: circleci/postgres:13.1, the build fails with: psycopg2.OperationalError: server does not support SSL, but SSL was required ... ... django.db.utils.OperationalError: server does not support SSL, but SSL was required (Complete traceback here) As a workaround, I'm using this image, which has Postgres with SSL certificate. (Complete config.yml here) Is there a better way to this? Possibly with a CircleCI container image of more recent versions of postgres? I haven't found anything in the CircleCI documentation regarding this. -
django template "grouped" tag don't gives me the grouped records as I wan't
I'm working on a project on django, I'm using the built in view ArchiveListView, and I want to sort records to be grouped by a common attribute. So django ORM don't have a group by query, so I tried to do this on the template using regroup tag, but I think it take a long time and it doesn't give me the grouped record as I want this is the models I have : class Vehicle(models.Model): serie = models.CharField(max_length=18, unique=True, blank=True, null=True) matricule = models.CharField(max_length=18, unique=True, blank=True, null=True) ww = models.CharField(max_length=18,blank=True, null=True) marque_id = models.ForeignKey('Marque', blank=True, null=True, on_delete=models.SET_NULL) entry_into_service = models.DateField(auto_now=False, auto_now_add=False, blank=True, null=True) mouchard = models.DateField(auto_now=False, auto_now_add=False, blank=True, null=True) extinguisher = models.DateField(auto_now=False, auto_now_add=False, blank=True, null=True, help_text="extincteur expiratiOn date") city_id = models.ForeignKey('City', blank=True, null=True, on_delete=models.SET_NULL) region_id = models.ForeignKey('Region', blank=True, null=True, on_delete=models.SET_NULL) driver_id = models.ForeignKey('Driver', blank=True, null=True, on_delete=models.SET_NULL) class Meta: ordering = ['serie','matricule'] def __str__(self): return (self.matricule) class GazStation(models.Model): name = models.CharField(max_length=128, blank=True) city_id = models.ForeignKey('City', blank=True, null=True, on_delete=models.SET_NULL) geo_localization = gis_models.PointField(blank=True, null=True) class Meta: ordering = ['city_id','name'] def __str__(self): return '%s %s' % (self.name, self.city_id.city) class Refuel(models.Model): vehicle_id = models.ForeignKey('Vehicle', blank=True, null=True, on_delete=models.SET_NULL) driver_id = models.ForeignKey('Driver', blank=True, null=True, on_delete=models.SET_NULL, limit_choices_to ={'is_driver':True}) Controlor_id = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='controlor_refuel', on_delete=models.SET_NULL, limit_choices_to ={'is_controlor':True}) … -
How to show search results of different models without refreshing the whole page
I have added search in my project but I am having a problem with one thing. When I write something in search field it returns me results of users, but when I click on tags to see tag results according to my search then my search text gets disappeares due to refresh or reloading of the page. I just want something by which my search stays there just like instagram. Here you can see I searched with the snap and got results of users and if I click on tags then it will show me tags results without again writing snap on search field for tags. I hope you understand what I'm asking for. -
WebSocket DISCONNECT after handshake with Django-EEL
I am trying to use EEL + Django. i found this solution in this GitHub link. I managed to make Django find the eel.js. but the issue it disconnect just after making WebSocket handshaking. as below:- You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, content types, sessions. Run 'python manage.py migrate' to apply them. January 31, 2021 - 17:22:47 Django version 3.1.5, using settings 'demo.settings' Starting ASGI/Channels version 3.0.0 development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. HTTP GET /example/operations 200 [0.03, 127.0.0.1:57173] HTTP GET /eel/eel.js 200 [0.01, 127.0.0.1:57173] Not Found: /favicon.ico HTTP GET /favicon.ico 404 [0.01, 127.0.0.1:57173] WebSocket HANDSHAKING /eel [127.0.0.1:57177] Exception inside application: object.__init__() takes exactly one argument (the instance to initialize) Traceback (most recent call last): File "D:\Python Projects\V1830Center\venv\lib\site-packages\channels\routing.py", line 71, in __call__ return await application(scope, receive, send) File "D:\Python Projects\V1830Center\venv\lib\site-packages\channels\routing.py", line 160, in __call__ send, File "D:\Python Projects\V1830Center\venv\lib\site-packages\asgiref\compatibility.py", line 33, in new_application instance = application(scope) File "D:\Python Projects\V1830Center\venv\lib\site-packages\channels\generic\websocket.py", line 23, in __init__ super().__init__(*args, **kwargs) TypeError: object.__init__() takes exactly one argument (the instance to initialize) WebSocket DISCONNECT /eel [127.0.0.1:57177] Project Tree: Settings.py """ Django settings for demo project. Generated by 'django-admin startproject' using Django … -
maximum recursion depth exceeded in ElasticSearch document
My BookingDocument (Elasticsearch Document) has an object type field, visitor: class VisitorDocument(InnerDoc): id = Integer() name = Text() def __init__(self, id, name): self.id = id self.name = name class BookingDocument(Document): visitor = Object(VisitorDocument) .... def setVisitor(self, id, name): self.booked_by = VisitorDocument(id, name) ... When I try to save: document = BookingDocument(meta={'id':id}) document.setVisitor("Visitor Name", visitor_id) I get: RecursionError at /booking maximum recursion depth exceeded while calling a Python object I don't see any loop in this code, why am I falling into this recursion limit? -
Heroku error during Django website deployment
I'm still getting this error after all the steps follow trying to solve. Can anyone help me pls. this is the error obtained from my PowerShell: heroku ps:scale web=1 Scaling dynos... ! ! Couldn't find that process type (web). Scaling dynos... ! ! Couldn't find that process type (web). This is the content of my Procfile located in my root: ��web : gunicorn grouppublishingindia.wsgi --log-file - The error I'm getting from my browser: -
Populate textarea after submit form
I have a small form created with Django forms.Form, consisting of title and description. After "submit", if there was an error, I go back to the form page. I would like the description field (a textarea) to be filled in with the text written before the "submit". -
django cache manager method (with arguments)
So I have a few models and a manager like this. class Member(BaseModel): objects = models.Manager() permissions = api_managers.PermissionManager() box = models.ForeignKey('api_backend.Box', on_delete=models.CASCADE) roles = models.ManyToManyField('api_backend.Role', through='api_backend.MemberRole') REQUIRED_FIELDS = [box, user] class Role(BaseModel): objects = models.Manager() positions = api_managers.PositionalManager() name = models.CharField(default='new role', max_length=100, validators=[MinLengthValidator(2)]) permissions = BitField(flags=permission_flags, default=default_perm_flags, db_index=True) is_default = models.BooleanField(default=False, db_index=True) position = models.PositiveSmallIntegerField(db_index=True, default=0) box = models.ForeignKey('api_backend.Box', on_delete=models.CASCADE) REQUIRED_FIELDS = [name, box] class MemberRole(BaseModel): objects = models.Manager() member = models.ForeignKey('api_backend.Member', on_delete=models.CASCADE) role = models.ForeignKey('api_backend.Role', on_delete=models.CASCADE) REQUIRED_FIELDS = [member, role] class Overwrite(BaseModel): objects = models.Manager() allow = BitField(flags=permission_flags, null=True, blank=True, db_index=True) deny = BitField(flags=permission_flags, null=True, blank=True, db_index=True) channel = models.ForeignKey('api_backend.Channel', on_delete=models.CASCADE, editable=False) box = models.ForeignKey('api_backend.Box', on_delete=models.CASCADE, editable=False) role = models.OneToOneField('api_backend.Role', on_delete=models.CASCADE, db_index=True) REQUIRED_FIELDS = [role, channel, box] from memoize import memoize class PermissionManager(models.Manager): def __init__(self): super().__init__() @transaction.atomic @memoize(timeout=3600) def get_overwrites(self, channel): assert channel.box == self.model.box, 'invalid channel given' permissions = self.get_base_permissions if channel.box.owner == self.model.user: return permissions try: # get the default everyone role's overwrite default_role = self.model.box.roles.get(is_default=True) default_overwrite = default_role.overwrite_set.get(channel=channel) except ObjectDoesNotExist: pass else: permissions &= set(~default_overwrite.deny) permissions |= set(default_overwrite.allow) member_role_ids = [role.id for role in self.model.roles.all()] overwrite_roles = channel.overwrites.filter(role__id__in=member_role_ids) deny, allow = None, None for overwrite in overwrite_roles: deny |= set(overwrite.deny) allow |= set(overwrite.allow) permissions … -
TemplateSyntaxError at / Invalid block tag on line 57: 'logout_url', expected 'endif'. Did you forget to register or load this tag?
I am building an app in Django. I dont' understand why I am getting TemplateSyntaxError at /login/ Invalid block tag on line 57: 'logout_url', expected 'endif'. Did you forget to register or load this tag? highlighting this line: <a class="nav-link" href="{% logout_url %}">Logout</a> Here is my code, In my urls.py: urlpatterns = [ path("logout/", LogoutView.as_view(), name="logout"), ] In my template: {% url 'logout' as logout_url %} {% if not request.user.is_authenticated %} <li class="nav-item {% if request.path == login_url %}active{% endif %}"> <a class="nav-link" href="{% url 'login' %}">Login</a> </li> <li class="nav-item {% if request.path == register_url %}active{% endif %}"> <a class="nav-link" href="{% url 'register' %}">Register</a> </li> {% else %} <li class="nav-item {% if request.path == admin_url %}active{% endif %}"> <a class="nav-link" href="{% url 'admin:index' %}">Admin</a> </li> <li class="nav-item {% if request.path == logout_url %}active{% endif %}"></li> <a class="nav-link" href="{% logout_url %}">Logout</a> <!-- logout_url --> </li> {% endif %} It works fine if I just substitute the part: <li class="nav-item {% if request.path == logout_url %}active{% endif %}"></li> <a class="nav-link" href="{% logout_url %}">Logout</a> </li> with: <li class="nav-item {% if request.path == logout_url %}active{% endif %}"></li> <a class="nav-link" href="{% url 'logout' %}">Logout</a> </li> But I don't understand why... It's like line {% url … -
How to set placeholders in django filters for fields in meta
How to set placeholders in django filters for fields in meta. Because for the field 'type, I already have predefined specific values for them to filter, so I cant use CharFilters etc like what I did for my end_date. Any idea? class TypeFilter(django_filters.FilterSet): end_date = DateFilter(field_name="date_published", lookup_expr='lte', widget=TextInput(attrs={'placeholder': 'MM/DD/YYYY'})) class Meta: model = Blog fields = ['type'] widgets = { 'type' : forms.TextInput(attrs={'placeholder': 'choose type'}), } -
Django jsonresponse for updating table makes the screen go black like opening a modal; can not close it
So if I update a author I want to update the candidates table with only the updated author and its new information. The problem is if I do that that the whole screen turns black like opening a modal. And the table is not updated but empty. If I do not do a call to process_author to update the table after update modal has been filled in there will not be a dark screen. Below is the code: <div id="authors-candidates-div"> <table id="authors-table" class="table"> <thead> <tr> <th class="text-center" scope="col">ID</th> <th class="text-center" scope="col">Name</th> <th class="text-center" scope="col">Name original language</th> <th class="text-center" scope="col">Extra info</th> <th class="text-center" scope="col">Update/ Link</th> </tr> </thead> <tbody> {% for author in authors.all %} <tr> <th class="text-center" scope="row">{{ author.pk }}</th> <td class="text-center">{{ author.name }}</td> <td class="text-center">{{ author.name_original_language }}</td> <td class="text-center">{{ author.extra_info }}</td> <td class="text-center"> <!-- Update author buttons --> <button type="button" id='init-btn{{ author.pk }}' class="btn btn-primary btn-danger" data-toggle="modal" data-target="#UpdateAuthorModal{{ author.pk }}"> <span class="fa fa-pencil"></span> </button> <!-- Modal --> <div id="UpdateAuthorModal{{ author.pk }}" class="modal fade" tabindex="-1"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title col-md-10">Update Author</h5> <button type="button" class="close" data-dismiss="modal">&times;</button> </div> <div class="modal-body"> <div class="form-group"> <label for="id_name_t">Name</label> <input type="text" name="name" maxlength="100" value="{{ author.name }}" class="form-control name" id="id_name{{ author.pk }}"> … -
How to simulate a User logging in with Selenium and Djangos LiveServerTestCase?
Currently working on an old Django project I want to finish and trying to write some tests using selenium for it. At this moment I and trying to test a user getting to the login screen and after typing the info in, they get redirected to the home page. The issue I am having though is this is having a user in the database. Since I didn't want the test info in the actual database, I wanted to use LiveServerTestCase. I created the User using the create_user() function in the setUp() part of the test. However when I ran the test, the user wasn't authenticated. After putting some print() statements in my test and view functions I found that I could see the user in the FT but then when it swapped to the view in the same test there were no User objects in the database. Below is more of my code from the tests/views. class TestNewUser(LiveServerTestCase): def setUp(self): self.browser = webdriver.Firefox() self.username = 'testuser' self.password = 'P@ssword9182' User.objects.create_user(username=self.username, password=self.password) print(User.objects.all()) Here's code from the FT They see a login screen with a username and a password input box login = self.browser.find_element_by_class_name('username') password = self.browser.find_element_by_class_name('password') button = self.browser.find_element_by_class_name('login_button') They … -
Mac: Running setup.py install for mysqlclient ... error
I am switching to mac from linux. In linux, i used to install mysqlclient in project enviroment and also globally when the app gave me error like "mysqlclient improperly configured". But in mac I couldn't seem to find a way. Here is the traceback below when I am trying to install mysqlclient in project enviroment. Collecting mysqlclient Using cached mysqlclient-2.0.3.tar.gz (88 kB) Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed. Installing collected packages: mysqlclient Running setup.py install for mysqlclient ... error ERROR: Command errored out with exit status 1: command: /Users/macbookpro/kalke-services/services/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/_k/74wl7dz56txbh904slsgt2180000gn/T/pip-install-1y50fx7i/mysqlclient_f48588e55e2a4270a35a2d3c79c1d000/setup.py'"'"'; __file__='"'"'/private/var/folders/_k/74wl7dz56txbh904slsgt2180000gn/T/pip-install-1y50fx7i/mysqlclient_f48588e55e2a4270a35a2d3c79c1d000/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/_k/74wl7dz56txbh904slsgt2180000gn/T/pip-record-fgig7hxx/install-record.txt --single-version-externally-managed --compile --install-headers /Users/macbookpro/kalke-services/services/venv/include/site/python3.8/mysqlclient cwd: /private/var/folders/_k/74wl7dz56txbh904slsgt2180000gn/T/pip-install-1y50fx7i/mysqlclient_f48588e55e2a4270a35a2d3c79c1d000/ Complete output (132 lines): mysql_config --version ['8.0.23'] mysql_config --libs ['-L/usr/local/opt/mysql-client/lib', '-lmysqlclient', '-lssl', '-lcrypto', '-lresolv'] mysql_config --cflags ['-I/usr/local/opt/mysql-client/include/mysql'] ext_options: library_dirs: ['/usr/local/opt/mysql-client/lib'] libraries: ['mysqlclient', 'resolv'] extra_compile_args: ['-std=c99'] extra_link_args: [] include_dirs: ['/usr/local/opt/mysql-client/include/mysql'] extra_objects: [] define_macros: [('version_info', "(2,0,3,'final',0)"), ('__version__', '2.0.3')] running install running build running build_py creating build creating build/lib.macosx-10.14.6-x86_64-3.8 creating build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/__init__.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/_exceptions.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/connections.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/converters.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/cursors.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/release.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb copying MySQLdb/times.py -> build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb creating build/lib.macosx-10.14.6-x86_64-3.8/MySQLdb/constants copying MySQLdb/constants/__init__.py -> … -
Getting pandas data into charts JS on a django site
I have a Django project that uses Pandas to make some data. Stats = df['criteria 4'].value_counts() print(Stats) Result: Pass 7 Fail 2 Not attended 1 What i am trying to do is put together a chart using charts js. The problem is nothing gets loaded. I can't figure out how to properly put the values from "Stats" into charts JS. Below is an empty charts JS template i put together. Anyone able to figure out how to get the data to appear in the graph? I have this JS code directly in my HTML code. <script> var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'doughnut', data: { labels: [], datasets: [{ label: 'Breakdown', data: [ ], backgroundColor: [], borderWidth: 1 }] }, options: { title: { display: true, text: }, responsive: false, } }); </script> -
Where should I place my context for the forms_as.p to work properly
basically, i'm trying to form.as_p to list the values but its not working. Its not really that its not working, but it only works (it only appears in my template) after i press submit. I believe I have placed the context in the wrong place or the wrong indentation but im not sure where i should shift context['form'] = form to. I tried to shift it but it says that lcoal variable referenced before assignment. Could someone advise? def create_blog_view(request): context = {} user = request.user if request.method == 'POST': form = CreateBlogPostForm(request.POST or None, request.FILES or None) if form.is_valid(): obj= form.save(commit = False) author = Account.objects.filter(email=user.email).first() obj.author = author obj.save() return redirect('HomeFeed:main') else: context['form'] = form return render(request, "HomeFeed/create_blog.html", context) -
Django/Nginx- How to pass url into function
I'm currently facing an issue that really drives me mad. I want to generate a secure download link (nginx secure link module) without using Javascript at all. To accomplish this I need to pass the download url over to the nginx signing function that generates the secure link via a shared secred between nginx and django. Afterwards the signed link should get returned to the user by a redirect. The problem now is that I always run into the following issue: TypeError: cypher_link_data() got multiple values for argument 'url' html: <a href="{% url 'cypher_link_data' url=post.postattachment.url %}">Download</a> signing function: def cypher_link_data(url): print(url) # sadly not reaching this point, so I can't tell you whats inside. secret = SOME_SECRET_VALUE future = datetime.datetime.utcnow() + datetime.timedelta(seconds=1) expiry = calendar.timegm(future.timetuple()) secure_link = f"{secret}{url}{expiry}".encode('utf-8') hash = hashlib.md5(secure_link).digest() base64_hash = base64.urlsafe_b64encode(hash) str_hash = base64_hash.decode('utf-8').rstrip('=') cypher_link = (f"{url}?st={str_hash}&e={expiry}") return redirect(cypher_link) url.py path('download<path:url>', auth_required(cypher_link_data), name='cypher_link_data'), the value of path:url is: /Data/user_upload/eb3b3141-b6ac-46fe-b394-9873af8c7d5a.png as you might note the missing slash after "download". The issue has to be at url.py and the processing of the url that gets passed to the signing function. I already checked onto https://docs.djangoproject.com/en/3.1/topics/http/urls/#path-converters with no succsess. What do I miss here? Please also note: I first implemented … -
Why does heroku install sqlite even if I already have a postgres database?
I'm starting to deploying applications to heroku and I connected my Django app to the hobby Django Database that heroku gave me for free. My question is, why if I have my app connected to postgres, heroku continues installing Sqlite in deployment? -
How to control whether to get style from in Vue MPA with Django webpack loader?
I'm building an app that uses Django for the backend, and integrates with a vue frontend using Django webpack loader module. Essentially, the frontend is configured as a multipage application and the end result is I can load and use vue components directly inide of django templates. Since I'm starting to see the complexity of my app grow, I want to switch over from using local <style>s inside of each components to having all the style stored together with my global styles. I also want to be able to access my sass variables (which are defined in my global styles, in a subdirectory that django uses to pull static files) from those styles. Here's what the project tree looks like: (I have hidden all the stuff that isn't relevant) . ├── django_vue_mpa │ └── static ├── __init__.py ├── static │ ├── grid-layouts.css │ ├── grid-layouts.css.map │ ├── grid-layouts.scss │ ├── style.css │ ├── style.css.map │ └── style.scss └── vue_frontend ├── babel.config.js ├── node_modules ├── package.json ├── package-lock.json ├── Pipfile ├── public ├── README.md ├── src ├── vue.config.js ├── webpack-stats.json └── yarn.lock I don't have a ton of experience with Vue MPA's. Looking at my vue.config.js, it looks like django_vue_mpa is … -
how do I check if something has had a value set to it in Django REST framework?
I have made an app back end now here's how it works user clicks on a product and a charge is made BUT the status is waiting How do I check in the background if the payment is waiting or confirmed? Reason I am asking this is because when it is confirmed then the product price which buyer bought is appended to the seller's balance model field. So I need to continuously in the background check if status is waiting or confirmed thanks in advance -
404 error when running local host command: django, python
when running the local host command, I get a 404 error. I have defined the empty ' ' path but the only URL paths that work are the '/admin', /posts/', and '/posts/about'. urls.py from django.urls import path from . import views urlpatterns = [ path('', views.home, name='Posts-Home'), path('about/', views.about, name='Posts-About'), ] views.py from django.shortcuts import render from .models import verdict posts1 =[ { 'author' : 'Tom E', 'title' : 'review1', 'content' : 'verdict1', 'date_posted' : 'today', }, { 'author' : 'Adam K', 'title' : 'review2', 'content' : 'verdict2', 'date_posted' : 'yesterday' } ] # Create your views here. def home(request): #puts data into dictionary context ={ #postkey 'reference' : verdict.objects.all() } return render(request, 'posts/home.html', context) def about(request): return render(request, 'posts/about.html', {'title': 'about'}) -
How to not reset form values in django admin
I am using Django-admin for inserting data. But when I submit, the form resets values, so I need to insert some of the fields again. Is it possible not to reset some of the field values? -
ModuleNotFoundError: No module named 'bootstrap4.bootstrap'
i'm learning about django-plotly-dash and i want to use bootstrap but i get error after install and here's its error: from bootstrap4.bootstrap import css_url ModuleNotFoundError: No module named 'bootstrap4.bootstrap'