I am using Django Contact Form within my application which requires the following addition to my urls.py file:
url(r'^contact/', include('contact_form.urls'), name='contactform'),
What I don't understand is the include() function:
include('contact_form.urls')
Looking in the Django Docs, I thought that using include() refers to another URLconf module but
having looked over the file system I can't find anything with this name which leads me to believe that my understanding of include() is not correct?
So can you tell me what or where this "contact_form.urls" is?
In case of need I am using Django 1.6. on Xubuntu 14.04.
Thanks in advance.
It's in the python path.
Presumably, you installed django contact form, which would put contact_form in your python path.
If you can't find it in your entire filesystem you're not looking hard enough!
python -c "import contact_form; print(contact_form.__file__)" would be another way to find where this physically exists.
Related
I'm trying to add django-messages to my app but I'm getting this error when I add it to my installed apps
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\encoding.py)
I've looked up this error and apparently it's caused by this line in Django-Messages models.py
from django.utils.encoding import python_2_unicode_compatible
To fix it I should change it to
from django.utils.six import python_2_unicode_compatible
As this is a third party app, how should I change this line?
Should I copy the file structure into my own project (creating a django-messages folder among my apps then a models.py file inside it) and copy/paste the entire models.py into there and then change the line? This seems wrong, but I don't know how else to fix it.
Or does the fact that it's using an outdated import signify that the app isn't maintained and therefore shouldn't be used at all?
Thank you.
I can suggest two options. First, you can clone it on GitHub (i.e. download all the files) and then paste this into your project folder (along with your other apps). And then you can make any changes you wish. Of course it remains to be seen whether it will work then, as there might be other issues. It seems to be compatible with Django 1.11 - 2.2. But I would think that it's a better option than doing this all yourself. Unless you can find a different app that suits your needs.
Second, assuming you are using a virtual environment, you can navigate to where all your packages are installed. I'm not sure where this will be located for you, but it should be something like envs\<name of env>\Lib\site-packages. And there you can make any changes you wish - just search for the relevant file.
Hope this helps.
Im about to deploy my django-app to heroku. I will then use whitenoise to handle the static files. The tutorial im following tells me i have to add this to my wsgi.py file:
So the problem is that pycharm tells me: "Cannot find reference 'DjangoWhiteNoise' in 'django.py'"
However i have installed whitenoise! and it is located in the "External libraries". I even went down into the whitenoise.django file, and there is nothing named DjangoWhiteNoise there...
Thanks in advance. Havent found anythin about this concrete problem anywhere.
The tutorial you are following is for an older, outdated version of WhiteNoise.
There are up-to-date instructions here:
http://whitenoise.evans.io/en/stable/django.html
In my project, I just added new security methods, separating the .env from the project into another folder and adopting the use of new processes. To do this, I followed the python-dotenv lib documentation, which I use in my app.
But even following the suggestion I can not find all the parameters, since I end up having the following error:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
My settings:
from dotenv import load_dotenv
env_path = Path('/home/user/configs') / '.env'
load_dotenv(dotenv_path=str(env_path))
How can I resolve this problem from the specific path?
Note: I use in my project, python 3.4.5 and django 1.9.4, but I do not believe that the problem is caused by the old versions adopted in the project.
Another important detail is that the .env file is correct, because when I use it in the same folder where I find the file settings.py it works without problems!
I'm also using this approach and from past few months I'm following a very good developer and he also writes about a python dependency "python-decouple" and you will going to get it in detail at this link
I think this will definitely going to solve your problem.
Python-decouple github repo : here
You can add the folder containing .env to the path. Here's how I did it:
load_dotenv(os.path.join(BASE_DIR, "project", ".env"))
Answered it here.
sometime simplest things are so complex!
I have some javascript which works fine. I decided to put it in a seperate javascript file that I want to link to my template.
I have put it in folder scripts/a_ajax.js off the root of the application.
Whatever folder structure I've tried has not worked.
I've also read something about that I must put a reference in urlpatterns but I'm not sure what I had to do.
Can anyone help tell me what I have to do to embed this code as a file?
thx
If your Django version is 1.3+: https://docs.djangoproject.com/en/dev/howto/static-files/
If your Django version 1.2.* or lower: https://docs.djangoproject.com/en/1.2/howto/static-files/
I've been pulling my hair out trying to solve this problem and I've tried everything and I have no ideas left.
I keep seeing this error:
Exception Value: 'thumbnail' is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module named sorl.thumbnail.main
$DJANGO_PACKAGES/sorl/thumbnail/main.py DOES exist.
Here's what I did to setup,
downloaded latest sorl-thumbnail and added its location to the python path in .bash_profile
included 'sorl.thumbnail' in INSTALLED_APPS (in django's settings.py)
used the {% load thumbnail %} tag in a django template
It would seem obvious sorl-thumbnail is not installed correctly, but I'm able to import thumbnail from the python shell and the django shell (when I use {% load thumbnail %} it brings this error). Also, there are no typos in related files (I've checked many many times).
I would venture to guess this is a $PYTHONPATH issue. Is it possible that the "thumbnail" directory is on the path and not "sorl"? I suspect this is the issue because you do not want to be able to type "import thumbnail" on the Python interpreter. You should instead have to type "import sorl.thumbnail".
Another thing to check is to print the module name after importing:
>>> import thumbnail
>>> print thumbnail
This will display the filesystem location where the module was found, in case it's loading another copy from somewhere you do not expect.
You also want to make sure your current working directory is not the root ../sorl/ location (ie. don't run python from the sorl folder). This will allow you to import thumbnail straight-away.
You should check your full Python path (it will be more than $PYTHONPATH) from within the python interpreter to verify your package locations:
>>> import sys
>>> print sys.path
It might also be helpful to learn more about Python importing
Problem solved.
When following the django book, it is suggested to create apps within a project directory and to refer to these apps in the INSTALLED APPS statement with a path that begins from the directory containing the project, for example, 'siteproject.books'. I was not able to give django access to apps without appending that directory name to the file path, so, for example, I was not able to simply use 'books', but needed to use 'siteproject.books' in the INSTALLED APPS statement and this was the case with sorl.thumbnail, which needed to be referred to as siteproject.sorl.thumbnail. Other attempts to include 'sorl.thumbnail' would yield a very ugly un-formatted and confusing purple-colored error page (yes, the sorl directory was in $PYTHONPATH, so who knows why these attempts didn't work...).
Unfortunately, Django was yielding the 'undefined tag' error, which is a generalized error that it gives in many situations. It doesn't really mean anything and isn't useful for locating problems.
The problem was solved when I opened the files in the sorl directory and edited the python files. I found import statements that imported objects from the sorl directory and I appended the 'siteproject.*' to those paths and everything began to work.
Here's another general tip on the unhelpful 'not a valid tag library' message: for tags that you create, it could be as simple as a syntax error.
Hat tip: 'Rock' on Django-users: http://groups.google.com/group/django-users/browse_thread/thread/d65db3940acf16c3?tvc=2