django-settings

how to check DEBUG true/false in django template - exactly in layout.html [duplicate]

笑着哭i 提交于 2019-12-03 10:32:13
问题 This question already has answers here : How to check the TEMPLATE_DEBUG flag in a django template? (6 answers) Closed 4 years ago . I would like distinguish a look of some toolbar in layout.html depending if DEBUG = True or not. I am aware of this answer using django.core.context_processors.debug but it forces me to use RequestContext instead of Request what I not really like, btw how can I use RequestContext for layout.html which extends base.html ? And generally is there some better way to

Bizarre error importing settings in django

我是研究僧i 提交于 2019-12-03 06:52:55
I have many projects working in ubuntu with python2.7 and virtualenv/virtualenvwrapper, in my work some developers works with macosx and windows, generally I create the project as usual: django-admin.py start project x And we use svn for cvs, but in some point, without nothing rational for me, when I try something like: python manage.py runserver doesn't work, but is just for me and is in my laptop, that doesn't happens in productions servers or another developers. any ideas? I got this error: Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've

Page not found 404 Django media files

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:40:54
问题 I am able to upload the files to media folder( '/peaceroot/www/media/' ) that I have set up in settings.py as below MEDIA_ROOT = '/peaceroot/www/media/' MEDIA_URL = '/media/' But through admin I tried to access the uploaded image file http://localhost:8000/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg then I am getting 404 error. The file exists at peaceroot/www/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg 回答1: Add media url entry in your project urlpatterns: from django.conf

Django: Obtaining the absolute URL without access to a request object

一笑奈何 提交于 2019-12-03 05:04:58
I have a model like the one below. When an instance is created, I want to send out an e-mail to an interested party: class TrainStop(models.Model): name = models.CharField(max_length=32) notify_email = models.EmailField(null=True, blank=True) def new_stop_created(sender, instance, created, *args, **kwargs): # Only for new stops if not created or instance.id is None: return # Send the status link if instance.notify_email: send_mail( subject='Stop submitted: %s' % instance.name, message='Check status: %s' % reverse('stop_status', kwargs={'status_id':str(instance.id),}), from_email='admin@example

how to check DEBUG true/false in django template - exactly in layout.html [duplicate]

这一生的挚爱 提交于 2019-12-03 01:03:08
This question already has answers here : How to check the TEMPLATE_DEBUG flag in a django template? (6 answers) I would like distinguish a look of some toolbar in layout.html depending if DEBUG = True or not. I am aware of this answer using django.core.context_processors.debug but it forces me to use RequestContext instead of Request what I not really like, btw how can I use RequestContext for layout.html which extends base.html ? And generally is there some better way to that than mentioned one or the one using custom template tag ? I am currently on Django 1.7 andilabs In newer versions of

Get absolute path of django app

怎甘沉沦 提交于 2019-12-02 21:57:05
I am writing a unit test that needs to access an image file that I put in "fixtures" directory right under my django app directory. I want to open up this image file in my test using relative path, which would require me to get the absolute path of the django app. Is there a way to get the absolute path of the django app? Python modules (including Django apps) have a __file__ attribute that tells you the location of their __init__.py file on the filesystem, so import appname pth = os.path.dirname(appname.__file__) should do what you want. In usual circumstances, os.path.absname(appname.__path_

What's the difference between `from django.conf import settings` and `import settings` in a Django project

五迷三道 提交于 2019-12-02 17:49:35
I'm reading up that most people do from django.conf import settings but I don't undertstand the difference to simply doing import settings in a django project file. Can anyone explain the difference? juliocesar import settings will import the first python module named settings.py found in sys.path , usually (in default django setups). It allows access only to your site defined settings file, which overwrites django default settings ( django.conf.global_settings ). So, if you try to access a valid django setting not specified in your settings file you will get an error. django.conf.settings is

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/

最后都变了- 提交于 2019-12-02 16:26:44
问题 I was following the django documentation and making a simple poll app. I have come across the following error : Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^admin/ The current URL, , didn't match any of these." settings.py ROOT_URLCONF = 'mysite.urls' mysite/mysite/urls.py from django.conf.urls import include,url from django.contrib import admin urlpatterns = [ url(r'^polls/',include('polls.urls')), url(r'^admin/', admin.site.urls),]

Python/Django - Avoid saving passwords in source code

无人久伴 提交于 2019-12-02 14:10:30
I use Python and Django to create web applications, which we store in source control. The way Django is normally set up, the passwords are in plain text within the settings.py file. Storing my password in plain text would open me up to a number of security problems, particularly because this is an open source project and my source code would be version controlled (through git, on Github, for the entire world to see!) The question is, what would be the best practice for securely writing a settings.py file in a a Django/Python development environment? Although I wasn't able to come across

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/

旧巷老猫 提交于 2019-12-02 10:04:26
I was following the django documentation and making a simple poll app. I have come across the following error : Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^admin/ The current URL, , didn't match any of these." settings.py ROOT_URLCONF = 'mysite.urls' mysite/mysite/urls.py from django.conf.urls import include,url from django.contrib import admin urlpatterns = [ url(r'^polls/',include('polls.urls')), url(r'^admin/', admin.site.urls),] mysite/polls/urls.py from django.conf.urls import url from . import views app_name= 'polls' urlpatterns=[