1👍
I don’t know exactly why /twitter/ view is called, but I can see two things to change:
- You should use a string as the second parameter for url(), as you can see in this example [1]. You can use ‘myapp.views.my_method’ nomenclature.
- You forgot to start the request URL with ^ that indicates the start of the URL.
About the unbounded code, I don’t know if that could be causing the problem. But I can’t see why are you putting that code unbounded. I am not sure when that code would be executed, I guess the first time you call a view in that file and Django loads the file (I’m guessing, I don’t know exactly), but I don’t think that would be a good way to do that. Think when do you want to execute that code, put it in a method, and call it.
[1] https://docs.djangoproject.com/en/1.5/topics/http/urls/#example
0👍
HI hemant i am wondering why you have written request_view.py.
Please see the django docs.
what you can do is .
Create two function in your views.py
like
def answer(request):
do some stuffs.
render_to_response(template.html)
and on the same page write another
def display_meta(request):
# do your studd
render_to_response(some.html)
YOU NEED NOT TO CREATE TWO SEPERATE VIEWS.PY
I dont know what this code does
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
keyword = input('enter the keyword you want to search for?')
stream.filter(track = [keyword])
But if you want to use StdOutListener
inside your function you can call in your view
like
def display_meta(request):
stobject = StdOutListener() # use parameters if you have here
# do your studd
render_to_response(some.html)
- [Answer]-Django Celerybeat PeriodicTask running far more than expected
- [Answer]-Is this a good use for django internationalisation
- [Answer]-Using In statement in django orm
- [Answer]-Python – proper syntax of .format()
- [Answer]-Type Error : 'authors' is an invalid key argument for this function
0👍
Organizing views into a python package could solve this problem. So if you have a structure like this…
# views.py
def SomeView(request):
return HttpResponse('SomeView')
# another_view.py
def AnotherView(request):
return HttpResponse('AnotherView')
Your can reorganize these separate view files into a views package. That is…
# views
# __init__.py
from views import SomeView
from another_view import AnotherView
# views.py
def SomeView(request):
return HttpResponse('SomeView')
# another_view.py
def AnotherView(request):
return HttpResponse('AnotherView')
And now, everything can be called in a django-standard way:
url(r'^url-to-some-view/$', 'views.SomeView'),
url(r'^url-to-another-view/$', 'views.AnotherView'),
UPDATED:
To make a ‘python package’…
- Create a
views
directory at the same level as theview.py
file [mkdir views
] - Create a
__init.py__
file inside theviews
directory # this is what makes a directory a ‘python package’ - Move
views.py
into theviews
directory. - Move your
request_view.py
into theviews
directory. -
Edit the
__init__.py
file with the necessary import statements. In this case:from views import answer from request_view import display_meta
What this does is replace a file with a directory. By importing everything into the __init__.py
file, this directory looks like a large file to your code, rather than another module.
- [Answer]-UserCreationForm has no field username
- [Answer]-Django Templatetag, request username
- [Answer]-Proper way to combine these base templates in Django?
- [Answer]-Switch model according to user