Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
unable to create superuser in Django pycharm
trying to create superclass for the first time using pycharm also i have installed pscopg2 and django but still (maybe) i see some issues related to importing psycopg2 it would be great if someone helps tried a lot but can't figure out... ** (untitled) C:\Users\User\PycharmProjects\untitled>python manage.py createsuperclass Traceback (most recent call last): File "C:\Users\User\PycharmProjects\untitled\lib\site- packages\django\db\backends\postgresql\base.py", line 25, in <module> import psycopg2 as Database File "C:\Users\User\PycharmProjects\untitled\lib\site-packages\psycopg2\__init__.py", line 51, in from psycopg2._psycopg import ( # noqa ImportError: DLL load failed while importing _psycopg: The specified module could not be found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\User\PycharmProjects\untitled\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\Users\User\PycharmProjects\untitled\lib\site-packages\django\core\management\__init__.py", line 377, in execute django.setup() File "C:\Users\User\PycharmProjects\untitled\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\User\PycharmProjects\untitled\lib\site-packages\django\apps\registry.py", line 114, in populate app_config.import_models() File "C:\Users\User\PycharmProjects\untitled\lib\site-packages\django\apps\config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen … -
Does Django index Autofield / ID keys in PostrgeSQL?
Django's docs state that id fields created with AutoField are indexed: id is indexed by the database and is guaranteed to be unique. Similarly it applies an index to every FK relationship. However, in PostgreSQL whilst FKs appear to be indexed, IDs are not. Here's an example: class TestModelBase(models.Model): name = models.CharField(max_length=50) fkfield = models.ForeignKey(TestModelFK, blank=True, null=True, on_delete=models.CASCADE) m2mfield = models.ManyToManyField(TestModelM2M, related_name='base_m2m') This model appears to apply the fkfield index, but not the id autofield. From PGAdmin below: Am I missing something? -
Gunicorn, error with Django: "ModuleNotFoundError: No module named 'store'"
The server uses Ubuntu 20.4 How looks my main folder: In src folder I have all Django structure: diasmart folder here is the project folder (contains settings.py, wsgi.py...) My apps in settings.py ... INSTALLED_APPS = [ ... # My apps 'store.apps.StoreConfig', 'orders.apps.OrdersConfig', 'profiles.apps.ProfilesConfig', ] My wsgi: import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'diasmart.settings') application = get_wsgi_application() gunicorn_config.py (main/gunicorn_config.py): command = '/root/DiaStore/env/bin/gunicorn' pythonpath = '/root/usr/bin/python' bind = '127.0.0.1:8001' workers = 2 user = 'root' limit_request_fields = 32000 limit_request_field_size = 0 raw_env = 'DJANGO_SETTINGS_MODULE=src.diasmart.settings' In bin folder (main/bin), I have "start_gunicorn.sh" file: (DiaStore its the name of the main folder) #/bin/bash source /root/DiaStore/env/bin/activate exec gunicorn -c "/root/DiaStore/gunicorn_config.py" src.diasmart.wsgi I wrote in terminal (DiaStore is the opened folder): source ./bin/start_gunicorn.sh I got: Traceback (most recent call last): File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/root/DiaStore/env/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File … -
Django autocomplete broken
I followed the solution in https://stackoverflow.com/a/55992659/13837243 because I was trying to filter my autocomplete fields. I made the override file in a folder in one of my apps at myapp/static/admin/js/. The autocomplete fields in that app stopped working. In fact, all autocomplete fields in my project (including in other apps) stopped working. I reverted the changes made, but still, autocomplete fields are all broken in my project. The autocomplete fields now look like normal dropdowns, except without any options. If a field already had an option selected, it looks like a normal dropdown that only displays the selected option. How can I fix this without potentially having to reinstall django? -
View does not update the current date (Django)
It is implemented to call get_week in view. 'now', which is printed directly as a template, is normally displayed, but the result of get_week, which is output through the module, is output as the value before 1 week. If you have fixed a similar bug, please help For reference, the source code below is a function to generate a weekly report. #: 금주 보고서는 read/modify @login_required def weekly_report_view(request): context = { 'site_title': '취약점 Dashboard', 'site_header': '취약점 Dashboard', 'user': request.user, 'has_permission': True, 'now': datetime.datetime.now() } this_week = False week_num = request.GET.get('week_num') if week_num is None: start_date, end_date, week_num = get_week() stats = Statistics2020.objects.filter(week_num=week_num) if len(stats) == 0: return redirect('/dashboard/stat/weekly/create') stat = stats[0] if stat.end_date >= datetime.date.today(): this_week = True stat_date_update(stat.week_num, stat.start_date, stat.end_date) else: pass context['stat'] = Statistics2020.objects.get(week_num=week_num) context['raw'] = json.loads(stat.raw) context['this_week'] = this_week return render(request, template_name='dashboard/weekly_report.html', context=context) def get_week(today=datetime.datetime.now().date()): shift = BASE_WEEK_START - 1 print(today) week_number = today.isoweekday() - shift if week_number <= 0: week_number += 7 startdate = today - datetime.timedelta(days=week_number-1) enddate = startdate + datetime.timedelta(days=6) #print('%s~%s'% (startdate, enddate)) return startdate, enddate, int(startdate.isocalendar()[1]) -
Execute celery task from model - Django
I have a model in my Django app: class MyTask(models.Model): id = models.AutoField(primary_key=True) name = models.CharField() I want to filter any MyTask object and assign a task to it, right now, I have like a "dummy" task which prints a message to console: from project._celery import _celery from celery.result import AsyncResult from django.apps import apps @_celery.task(name="print_object") def print_object(bind=True): model = apps.get_model(app_label='my_app', model_name='MyTask') new = model.objects.filter(pk__in=[1,2,3]) new.task = app.AsyncResult.task_id print("Hello, I'm an Object!") I just want to assign this task, to MyTask objects having pk's 1,2 and 3. I know that with model = apps.get_model(app_label='my_app', model_name='MyTask'), I can access my model. But, in any case, this line says: NameError: name 'MyTask' is not defined I do have the apps.py file on my app directory: from django.apps import AppConfig class MyAppAppConfig(AppConfig): name = 'my_app' So, no idea why this is happening, btw, my tasks.py file is inside a folder, inside my module folder, could that be the cause for this? Also, from what I want to achieve, do you think this is the ebst way to do it? Thanks in advance -
Why user.is_active is false if the username and password are stored in the database?
Every time I try to log in in the website I created, it returns the else in the user_login function in views.py, but I don't understand why since it stores correctly in Users in the database. views.py from django.shortcuts import render from django.contrib.auth import authenticate, login, logout from django.urls import reverse from django.contrib.auth.decorators import login_required from django.http import HttpResponseRedirect, HttpResponse from django.contrib.auth.models import User from .forms import UserForm # Create your views here. def index(request): return render(request, 'app1/index.html') @login_required def user_logout(request): logout(request) return HttpResponseRedirect(reverse('index')) def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() registered = True else: print(user_form.errors) else: user_form = UserForm() return render(request, 'app1/register.html',{'user_form':user_form, 'registered':registered}) def user_login(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = authenticate(username = username, password = password) if user: if user.is_active: login(request, user) return HttpResponseRedirect(reverse('index')) else: return HttpResponse("Account Not Active") else: print("Someone tried to login and failed") print(f"Username: {username} and password {password}") return HttpResponse ("Invalid Login details supplied") else: return render(request, 'app1/login.html',) forms.py from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm class UserForm(forms.ModelForm): password = forms.CharField(widget=forms.PasswordInput()) class Meta(): model = User fields = ('username','email', 'password') models.py from … -
How to solve Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings issue
I am running on Windows 10 and have successfully installed the gdal 64 bit library from this resource: https://trac.osgeo.org/osgeo4w/ My django app is running with pipenv I also added in my settings.py the variable : GDAL_LIBRARY_PATH = 'C:\OSGeo4W64\bin' and also add this variable also to the path variable ins system variables. After every run of the development server i got the error : Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Users\Maria\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\Maria\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run autoreload.raise_last_exception() File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception raise _exception[1] File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\core\management\__init__.py", line 357, in execute autoreload.check_errors(django.setup)() File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\apps\registry.py", line 114, in populate app_config.import_models() File "C:\Users\Maria\.virtualenvs\ev-loader-backend-7qq6TCvy\lib\site-packages\django\apps\config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "C:\Users\Maria\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed … -
how to add speech recognition to a web app?
I would like to someone to guide me to know how to add speech recognition to a web app, specifically to Zoom Meetings within a web app. The main idea is to get into text the meetings using Django. I trained a CNN model using tensorflow, but I was seeing that I will not be able to use it within the web app using django, because I'm using pyaudio library, which captures the internal audio of the computer. The same will happend using the standar library SpeechRecongnition. Maybe it is possible using the Zoom's API and some property that can be used in django or using speech regonition API from google. Any guidance or scope someone can do to both the answer and the question will be considered -
CSS all properties not working with Django/bootstrap
I'm trying to create some custom css. I'm using django and a bootstrap template to have something to begin with. I'm trying to use this css: a { position: relative; display: inline-block; padding: 15px 30px; color: #f02720; text-transform: uppercase; text-decoration: none; font-size: 24; overflow: hidden; transition: 0.2s; } a:hover { color: #255784; background: #2196f3; box-shadow: 0 0 10px #2196f3, 0 0 40px #2196f3, 0 0 80px #2196f3; transition-delay: 1s; } Things like the changing the color work, but some don't. Is there a reason why? Are there limitations because I'm also using bootstrap? -
Getting error notices while developing with Django - Visual Studio
I started to use the framework Django on Visual Studio Code, and even though my code is correct and works just fine when I run it, Visual Studio keeps sending error warnings (see pic), which is something that it never does when I don't use the Django framework. When I code in Python without using the Django framework and Visual Studio signals an error, then there is actually something wrong with my code, but when using Django it seems that it signals errors even tho the code is perfectly fine. I thought about switching off the feature completely, but it's a very convenient feature, when it works properly. How can I set Visual Studio in a way that when working with Django, it signals errors only when there is actually something wrong with the code? -
Django update fields on POST request when unique username field unchanged
I have a simple profile form that displays the users profile and allows them to make updates to Full Name, Initials, Username and Bio. In my Profile model, I have Username set to unique with field validation. It is more of a screen-name reference field, as email is used for login, however it still needs to be unique and the user can change this name if needed. The issue is that validation does not allow for POST form.save(), even when user does not change their username, but updates other fields, due to the fact that the username does already exist for the request user. How can I get around this issue. Sample of what i am trying to do: If request.user.username == form['username'].value() (meaning username is unchanged) allow form.save() else if form.is_valid(): (perform normal validation checks) form.save() Thanks for any suggestions. -
Error adding a convential sign up and github sign up together in a django project
I am doing a django book store project which has a successful sign up function. I followed WS Vincent's tutorial to connect Github signup (https://learndjango.com/tutorials/django-allauth-tutorial) and I have come across an error when integrating it. TemplateSyntaxError at / Invalid block tag on line 16: 'provider_login_url', expected 'endif'. Did you forget to register or load this tag? Below is the code for the major areas of my project. home.html {% extends '_base.html' %} {% load static %} {% block title %}Home{% endblock title %} {% block content %} <h1>Homepage</h1> <img class="bookcover" src="{% static 'images/djangoforprofessionals.jpg' %}"> {% if user.is_authenticated %} <p>Hi {{ user.email }}!</p> <p><a href="{% url 'account_logout' %}">Log Out</a></p> {% else %} <p>You are not logged in</p> <p><a href="{% url 'account_login' %}">Log In</a> | <a href="{% url 'account_signup' %}">Sign Up</a> <a href="{% provider_login_url 'github' %}">Sign Up</a></p> {% endif %} {% endblock content %} I am not familiar with HTML but I take the two sign up lines are not meant to be put one after the other. -
How can I test Django Channels using native Django's test framework instead of pytest?
Django Channels recommends using pytest in order to get an async enabled testing layer. I really don't want to throw another test framework into my project if I can help it. Is there a way to use Django's TestCase natively to test Django Channels? I've encountered multiple problems -- one is that async_to_sync() doesn't like to be called from the main thread. I am limited with Python 3.6 at the moment. -
is there another way to add a real-time update for your django app
I just have two questions: * is there another way to add a real-time update for your django app rather than using Django channels? please if there is another way let me know because django channels requires a lot of changes on the server settings and it's just a pain on the ass to impliment them. I once used Pusher instead of django channels and websockets It just worked well on my app and i didn't have to install django channels and my app worked just fine on WSGI mode? I'm really confused how this was even possible if any one here is an expert on the subject can you please explain how Pusher works and why we need Django channels in the first place since as far as i can see implimenting pusher with django is so much easier than using django channels. thanks in adnvace -
Object is not subscriptable in django
I have this function in django: def get_customer(request): resp = dict(succees=False, message='no se encontro clientes') database = request.user.company_select.company_db try: customers = Customer.objects.using(database).get(id_customers=request.data['id_customer']) if customers: list_customers = list() customers['subgroup_p'] = Customer_Subgroup.objects.using(database).values().filter(id_subgroup=customers['customers_subgroup']) customers['group_p'] = Customer_Group.objects.using(database).values().filter(id_group=customers['subgroup_p']['group_id']) customers['customers_subgroup_p'] = Catalog_Type_Customer.objects.using(database).values().filter(id_type_customer=customers['customers_type']) customers['city_p'] = City.objects.values().filter(city_id=customers['city']) customers['state_p'] = State.objects.values().filter(state_id=customers['city_p']['state_id']) customers['country_p'] = Country.objects.values().filter(country_id=customers['state_p']['country_id']) list_customers.append(customers) resp.update(dict(success=True, message='', customers=list_customers)) except Exception as e: print(e) resp.update(dict(message='Error')) return Response(resp) But i get the error ´Customer´ is not subscriptable What can i do to solve this? Thanks! -
Django + Chart.js Am I Doing This Right? Nothing is being rendered
#views.py from django.shortcuts import render from django.views import View class home_view(View): template_name = "home.html" def get(self,request,*args,**kwargs): request.session.flush() ##fixed an issue (session data corrupted) user = request.user form = QuestionnaireForm() context = { 'user': user, 'form': form } return render(request,self.template_name, context) def post(self,request, id=None, *args, **kwargs): user = request.user form = QuestionnaireForm(request.POST) if form.is_valid(): form.save() context = { 'user': user, 'form': form } return render(request,self.template_name, context) class RandomView(View): def get(self, request, *args, **kwargs): return render(request, 'api-chart.html') #urls.py from django.contrib import admin from django.urls import path, include from django.conf.urls import url from pages.views import home_view, RandomView path('', home_view.as_view(), name='home'), url(r'^chart/$', RandomView.as_view(), name='test'), #api-chart.html {% extends 'base.html' %} <script> {% block jQuery %} var ctx = document.getElementById('myChart'); var myChart = new Chart(ctx, { type: 'bar', data: { labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], backgroundColor: [ 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)' ], borderColor: [ 'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)' ], borderWidth: 1 … -
Extending base_site.html using Jinja2 Templating (Migrating from Django Templating)
I'm looking into the feasibility of switching from Django Templating to Jinja2. We heavily use the base admin files and Jinja seems to be having trouble locating the base files. Is there a way to extend them in Jinja2 without needing to copy and paste the files to the jinja2 directory I created in app? Or do I simply have it misconfigured? Hard a hard time locating an answer to my question elsewhere. settings.py { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR + '/templates/', BASE_DIR + '/www/'], 'APP_DIRS': False, 'OPTIONS': { 'debug': DEBUG, 'context_processors': [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], 'loaders': ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', 'public.loaders.DatabaseLoader', ) }, }, { 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'environment': 'notify_me.jinja2.environment', }, }, ] jinja2.py from django.contrib.staticfiles.storage import staticfiles_storage from django.urls import reverse from jinja2 import Environment from django.contrib import admin from django.template.context_processors import request, i18n, debug, media, static, tz from django.contrib.auth.context_processors import auth from django.contrib.messages.context_processors import messages def environment(**options): env = Environment(**options) env.globals.update({ 'static': staticfiles_storage.url, 'url': reverse, }) return env my_file.html (under app/jinja2/admin/my_file.html) {% extends "admin/base_site.html" %} The Exception jinja2.exceptions.TemplateNotFound: admin/base_site.html -
I connected my Django app to MLabs, what do I do now to be able to migrate my database structure to it?
I successfully connected my Django app on my computer to Mlab using Djongo and the homepage on my localhost:8000 server seems to be displaying correctly. However, when I run 'py manage.py migrate', it gives a long list of errors in the terminal and I am not sure how to properly connect to the Mlabs database and populate it with data from the terminal of my Django app in my local computer. How do I migrate the database information onto my Mlab database? I'm not sure what the error is. I'm a little new to Django and MongoDB. This is a part of the error I see: The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Users\simon\AppData\Local\Programs\Python\Python38\lib\site-packages\djongo\cursor.py", line 51, in execute self.result = Query( File "D:\Users\simon\AppData\Local\Programs\Python\Python38\lib\site-packages\djongo\sql2mongo\query.py", line 783, in __init__ self._query = self.parse() File "D:\Users\simon\AppData\Local\Programs\Python\Python38\lib\site-packages\djongo\sql2mongo\query.py", line 868, in parse raise exe from e djongo.exceptions.SQLDecodeError: Keyword: None Sub SQL: None FAILED SQL: INSERT INTO "django_migrations" ("app", "name", "applied") VALUES (%(0)s, %(1)s, %(2)s) Params: ['contenttypes', '0001_initial', datetime.datetime(2020, 7, 29, 21, 36, 46, 283726)] Version: 1.3.3 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Users\simon\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 86, … -
one user viewing another users profile in django
ive been searching the web for answers any help would be appreciated in my app i need to add a functionality where one user can view another users profile view.py class profile(models.Model): user = models.OneToOneField(User, on_delete = models.CASCADE) bio = models.TextField(blank=True) def __str__(self): return f'{self.user.username} profile' html: {% for post in posts %} <div class="icl-NavigationList-item"> <div class="icl-NavigationList-link icl-NavigationList--primary"> <div class="icl-NavigationList-text"> <h2 class="icl-NavigationList-title"> <div class="upperText"> <h2 class="card-title"style="background-color:{{post.post_colours}};">{{post.job_title}}</h2> <a class="a-tags" href="*{{ i need to link the post author here}}*" data-tippy-content="@dribble_handle"> <img src="{{post.author.profile.profile_pic.url}}" style="border-radius: 100%;float:right;" alt="author"width="30" height="30"></a></div> <div class="lowerText"> <p class="card-text">{{post.currency}} {{post.salary}}</p> <p class="card-text"> Posted on {{post.date_posted}} by {{post.author}} </p> <br> {% if user.is_authenticated %} -
Why cant i show the profile picture in my web page?
Im learning django from a project tutorial and i got stuck on a problem. The problem is: Internal Server Error: /account/ Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\base.py", line 828, in _resolve_lookup current = current[bit] TypeError: 'ImageFieldFile' object is not subscriptable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\core\handlers\base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\core\handlers\base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view return view_func(request, *args, **kwargs) File "C:\Users\user\Desktop\crm1\accounts\decorators.py", line 23, in wrapper_func return view_func(request, *args, **kwargs) File "C:\Users\user\Desktop\crm1\accounts\views.py", line 107, in accountSettings return render(request, 'accounts/accounts_settings.html', context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\shortcuts.py", line 19, in render content = loader.render_to_string(template_name, context, request, using=using) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\loader.py", line 62, in render_to_string return template.render(context, request) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\backends\django.py", line 61, in render return self.template.render(context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\base.py", line 171, in render return self._render(context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\loader_tags.py", line 150, in render return compiled_parent._render(context) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\django\template\base.py", … -
STATIC FILES PYTHON ANYWHERE
When I run python manage.py collectstatic in the bash console of pythonanywhere I keep getting "python: can't open file 'manage.py': [Errno 2] No such file or directory". But I can clearly see my manage.py file in my code editor, I am a beginner in django and its pretty frustrating. If anyone has any ideas what this can possibly be, I would love your help. Thanks settings.py -
Django Fixtures: Validate before applying
This morning I pushed out an update to our application that added a unique constraint to one of our fields. As part of our deployment, we applied the fixtures and ran across an issue where there was a duplicate in the DB. This created an error in our deployment and gave our users 502 errors for a short time. I am automating our deployment processes and To keep this from happening again, would like to perform some kind of validation on the fixtures before they are applied to the DB. Is there a way to do this in django? Thanks! -
how to add multiple items from the list and add it to text field. and also i want to add item by typing in the input field
<form class="form-horizontal" method="POST" > <div class="form-group col-md-5" > <label for="skill">Skill</label> <input type="text" name="skill" class="form-control"> <select multiple class="form-control" name="taqinput"> <option>css</option> <option>html</option> <option>c++</option> </select> </div> </form> for example if i click on css the css will add into inputfield and also when i write math in the input field it will also be added. -
What is Django Rest API?
I have been learning django from last 1 month,but then i got to see a new term django rest API,so now i am trying to figure out whats the difference between them.Can anyone tell me what's actually the difference between 'django' and 'django rest API', where it is used and should anyone learn it or not?