I just finished installing Python and Django. I followed everything in a tutorial video and I wrote the most simple code:
from django.shortcuts import render
from django.http import HttpResponse
def hello(request):
return HttpResponse("<h1>Hello world!</h1>")
I imported it to the URL and it works as expected but the problem is I get this error:Unable to import I don't know why it is saying this because it works well. what is wrong with the program?
And I have the same import problem on other files too.
Related
I am getting an import error as i try to import gensim, pandas and numpy in django views.py . It works fine in shell.
How can I import them in views.py. I have installed the libraries in virtual environment.
I am getting this error when I use templates:
ImportError: No module named templates.backends.django
If I use an HttpResponse the page shows up, but I get this error with the render function.
views.py:
from django.shortcuts import render
def login(request):
return render(request,'/test.html')
I'm using python 2.7.12
I'm trying to learn Django, so I completed their multi-part tutorial (Python 2.7) and ran it locally. I got it working fine on my PC.
I need the following import, in a views.py file:
from django.urls import reverse
When I upload it to GAE, it gives me the following error:
Exception Type: ImportError
Exception Value: No module named urls
Is this module unavailable for the GAE, or am I doing something wrong?
(By the way, I need this import so I can use the "reverse" method, after a user submission is received in the polls app, like: HttpResponseRedirect(reverse('polls:results', args=(question.id,))) )
reverse() was moved from django.core.urlresolvers to django.urls in Django 1.10. The error suggests that you are using an older version of Django.
You need to import reverse() from the old location:
from django.core.urlresolvers import reverse
I'm having a problem trying to use class based views in django.
When I try to import the base View I get an import error.
I've simplified my view down to the exact same code as used in the documentation:
from django.http import HttpResponse
from django.views.base import View
class MyView(View):
def get(self, request):
# <view logic>
return HttpResponse('result')
The error I'm getting is
ImportError at /myurl/
No module named base
urls.py are fine and Django is definitely version 1.5 - I've completely reinstalled it with pip, any ideas?
Because of #dm03514 comment I test it. I try your code in your question and I got the same error with you "No module named base". So when I change it to, like the codes below, it works and no error.
from django.views.generic.base import View
Try before judging, I will accept it if it is wrong and I will try to fix it.
I'm running Django (1.4.3) with dajaxice (0.5.4). I have a file ajax.py with my functions in the main project folder called prj, which looks like:
from dajax.core import Dajax
from dajaxice.decorators import dajaxice_register
from django.utils import simplejson
from dajaxice.core import dajaxice_functions
from django.core.urlresolvers import reverse, resolve
def getContent(request, *args, **kwargs):
url = kwargs['url']
try:
v = resolve(url)
except:
data = []
data.append(('some','data'))
return simplejson.dumps(data)
dajaxice_functions.register(getContent)
I ran python manage.py collectstatic, and I get the following output:
Copying '/tmp/tmpm8OlOw'
However, the dajaxice.core.js generated does not have my function getContent at all. Where am I going wrong? I have dajaxice installed properly and everything, I hope.
Seems you forgot to call dajaxice_autodiscover() from urls.py (this is the place recommended by dajaxice author)
this call will load ajax.py module and make it's method discoverable by JS code generator
You need to register you function with dajaxice either using #dajaxice_register decorator or other methods mention in the documentation.
http://django-dajaxice.readthedocs.org/en/latest/quickstart.html#create-your-first-ajax-function