django-views

custom template loader Django

久未见 提交于 2021-02-07 09:51:03
问题 i am trying to write a custom template loader in django which serves index.html which is present in a s3 bucket. Following is my loader file from django.conf import settings from django.template import Origin, Engine from django.template.loader import TemplateDoesNotExist from django.template.loaders.base import Loader from boto3.session import Session ACCESS_KEY_NAME = getattr(settings, 'AWS_TEMPLATE_LOADING_ACCESS_KEY_ID', getattr(settings, 'AWS_TEMPLATE_LOADING_ACCESS_KEY_ID', None))

how to fix the 'AnonymousUser' object has no attribute 'profile' error?

╄→гoц情女王★ 提交于 2021-02-07 06:48:43
问题 I'm writing a chat app for a hypothetical social network but when I try to open the chat page I give the following error 'AnonymousUser' object has no attribute 'profile' error . I think there may be problem in the models file but I can't really figure out how to fix it and I'm really confused now!? can anyone give any suggestions?? parts of the chat views.py def index(request): if request.method == 'POST': print request.POST request.user.profile.is_chat_user=True logged_users = [] if request

include() got an unexpected keyword argument 'app_name'

家住魔仙堡 提交于 2021-02-07 06:10:27
问题 i am making a blog application for my website with django-2.0 when i run server i see the following error File "C:\Users\User\Desktop\djite\djite\djite\urls.py", line 7, in <module> url(r'^blog/', include('blog.urls', namespace='blog', app_name='blog')), TypeError: include() got an unexpected keyword argument 'app_name' here is my main urls.py from django.contrib import admin from django.conf.urls import url,include urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^blog/', include(

include() got an unexpected keyword argument 'app_name'

五迷三道 提交于 2021-02-07 06:06:43
问题 i am making a blog application for my website with django-2.0 when i run server i see the following error File "C:\Users\User\Desktop\djite\djite\djite\urls.py", line 7, in <module> url(r'^blog/', include('blog.urls', namespace='blog', app_name='blog')), TypeError: include() got an unexpected keyword argument 'app_name' here is my main urls.py from django.contrib import admin from django.conf.urls import url,include urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^blog/', include(

migrations are not taking place after pushing my code on heroku…?

送分小仙女□ 提交于 2021-02-05 11:34:09
问题 Well its been 12 hours and i'm still unable to deploy my project properly. I just dont know what is wrong happening. You guys can see throughing error that such models not exist . But i'm trying to make migrations my heroku run python manage.py makemigrations and it throughing me this traceback. My code is working perfectly fine in local but on the server side this is happening. Please help me out. Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage

how to name numerous dynamic input fields for post method - Django

对着背影说爱祢 提交于 2021-02-05 10:39:48
问题 In my online shop, I fetch all of the products and services from two different apps and list them for the user to make his wishlist. Each product or service is displayed in a bootstrap card that contains an input field for the count of products. #views.py def my_products(request): ip_sensor = Ip_sensor.objects.all().order_by('title') control_valves = ControlValves.objects.all().order_by('title') context = { 'ip_sensor': ip_sensor, 'control_valves': control_valves, } return render(request,

how to name numerous dynamic input fields for post method - Django

时光怂恿深爱的人放手 提交于 2021-02-05 10:38:03
问题 In my online shop, I fetch all of the products and services from two different apps and list them for the user to make his wishlist. Each product or service is displayed in a bootstrap card that contains an input field for the count of products. #views.py def my_products(request): ip_sensor = Ip_sensor.objects.all().order_by('title') control_valves = ControlValves.objects.all().order_by('title') context = { 'ip_sensor': ip_sensor, 'control_valves': control_valves, } return render(request,

How to format current time in django views?

蓝咒 提交于 2021-02-05 09:24:27
问题 I'm unable to figure out that how to format present time in django views. I just want to show year-month-date or (y,m,d) .Can you guys tell me how to do this ? Right now i'm trying in a following way. from django.utils import timezone print('date :',timezone.now()) and it returns : date : 2020-12-31 18:34:29.309006+00:00 Desire output is : date : 2020-12-31 回答1: from datetime import datetime my_date = datetime.now().strftime("%Y-%m-%d") 来源: https://stackoverflow.com/questions/65524569/how-to

How can i Edit/Change the value of a model field from views.py

我们两清 提交于 2021-02-05 08:40:51
问题 Good-day everyone. I want to know how i can change the value of a model-field through the number of items in a defined sessions list I have already made a profile model (which is OneToOne Field to the user model) with a 'level' field as shown below in my models.py; And in view.py, I have created a session called 'answer_list' which is a list that stores all correct answers provided by the user. models.py class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models

How can i Edit/Change the value of a model field from views.py

倾然丶 夕夏残阳落幕 提交于 2021-02-05 08:39:07
问题 Good-day everyone. I want to know how i can change the value of a model-field through the number of items in a defined sessions list I have already made a profile model (which is OneToOne Field to the user model) with a 'level' field as shown below in my models.py; And in view.py, I have created a session called 'answer_list' which is a list that stores all correct answers provided by the user. models.py class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models