is it possible to to a step through the code in django ( i mean step through while debugging)
Yes, you can do that by using the Python Debugger module, pdb. I have covered the topic of debugging Django applications on my blog before. In an nutshell, if you are using the Django development server, you can easily step through your Django application by placing a breakpoint with the statements import pdb; pdb.set_trace() at any point in your view code where you want to start debugging, and then step through the debugger that is invoked on the shell where the Django development server was running from.
Yes, as long as you're running in the development server.
If so, just put this into your code at the point you want to stop:
import pdb; pdb.set_trace()
and you will be dumped into the debugger on the console, from where you can step through to your heart's content.
To address debugging, instead of step-based debugging in the framework itself it is more preferable in the Django community to provide unit tests. If you are building a module, Django provides facilities to test applications. For step-through debugging you may need an IDE to handle it: AFAIK Django doesn't provide a facility to do that.
Related
I'm using Pycharm to write a Django App with React as the frontend. Because the React source code is inside the Django source code, there is no clear way to trans-compile the React source code.
I know Pycharm can compile the code if it is a React project, but there are no instructions for compiling if it is embedded in a Django project.
I don't have a list of things I've tried because I have no idea where to start other than doing searches on Google, which I've already done.
I did look at the file-watcher in Pycharm, but it is not clear if this is a solution because there is nothing React related in it.
I think the proper way to go about this is to have two different projects, one for Django and one for React; you can then attach them later in one window, if you want (just open one, then the other - you will be prompted about what to do with the second).
I am looking for a guide to migrate Django project to Google App Engine and use Google's datastore. The most of the guides I found were linked to Django-Appengine using Django-nonrel (but I want to use GAE's native support).
Going through GAE getting started guide, it says:
Google App Engine supports any framework written in pure Python that speaks CGI (and any WSGI-compliant framework using a CGI adaptor), including Django, CherryPy, Pylons, web.py, and web2py. You can bundle a framework of your choosing with your application code by copying its code into your application directory.
I understand that I won't be able to use some features of Django in that case (majorly the admin feature) and would also need to restructure the models.
From other reading, I also found that latest SDK of GAE now includes Django 1.3 on Python 2.5.
I tried to put all files from my Django application to a GAE project, but couldn't get it all to work together.
Please provide some basic guide using which I may migrate my Django project to Google App Engine's code.
Thanks.
For an existing Django app, using django-nonrel is the simplest approach; it is very popular so you should be able to find help with specific errors you get quickly.
Another approach is written up in this article: http://code.google.com/appengine/articles/pure_django.html -- it goes the other way, taking an App Engine app that uses Django for dispatch, templates, and forms, but not for models, and describes how to make it run in a native Django environment. Maybe you can glean some useful hints for your situation from it.
I've used django-nonrel, which behaves pretty much like django, except that operations with JOINs will return errors. I've basically worked around this by avoiding ManyToMany fields, and essentially building that functionality manually with an intermediate table.
So far I've ran into two problems with Django-nonrel:
1. No access to ancestor queries, which can be run in a transaction. There's a pending pull request for this feature though.
2. You can't specify fields that are not indexed. This could significantly increase your write costs. I have an idea to fix this, but I haven't done so yet.
(Edit: You CAN specify fields that are not indexed, and I've verified this works well).
2 (new). Google is pushing a new database backend called ndb that does automatic caching and batching, which will not be available with django-nonrel.
If you decide not to use django-nonrel, the main differences are that Django models do not run under App Engine. You'll have to rewrite your models to inherit from App Engine's db.Model. Your forms that use Django's ModelForm will need to inherit from google.appengine.ext.db.djangoforms instead. Once you're on App Engine, you'd have to port back Django if you ever take your app somewher else.
If you already have a Django application you might want to check this out. You won't work with App Engine's datastore but Google Cloud SQL might fit your needs.
I have an application built with Django. Part of it relies on data that I aggregate from other websites. Wondering how I should approach building the scraper/aggregator.
The advantages I see of building it as a Django app is
the ability to use Django's models & database API
the ability to use Django's other methods
On the other hand I think the disadvantage would be scalability in the long run.
Should I build the scraper/aggregator as an app in my Django project or as a separate script that runs on its own?
Would love to hear your thoughts.
Neither of your points require it to run within Django. And since it will not be dependent on the web/HTTP interface, having it be a separate module is the only option that makes sense.
I just have published a Django app django-dynamic-scraper on GitHub, which is build on top of the scraping framework Scrapy and where you can build Scrapy scrapers in the Django admin and use Django model classes to store your scraped data, maybe this is of some use for people with similar problems.
If it's a django app, it will only run when someone loads the page. That could slow the loading.
Making another script could be a nicer idea but could produce inaccurate data.
I think it actually depends on the context.
I have moved my Django app from my development machine (OS X, Python 2.6.5, Django 1.2.3) to a staging server (Ubuntu VM, Python 2.6.6, Django 1.2.3).
If I now run my test suite on the staging server, two tests fail when using the Django TestClient because response.context is None (but response.content is correct).
For example:
self.assertEquals(self.session.pk, response.context['db_session'].pk)
These test cases pass on the development machine.
Has anybody encountered similar problems?
You need to add the test setup statement.
import django
django.test.utils.setup_test_environment()
Find more details by following my link:
http://jazstudios.blogspot.com/2011/01/django-testing-views.html
From Django documentation:
Although * your code * [+] would work in the Python interactive interpreter, some of the test client's functionality, notably the template-related functionality, is only available while tests are running. The reason for this is that Django's test runner performs a bit of black magic in order to determine which template was loaded by a given view. This black magic (essentially a patching of Django's template system in memory) only happens during test running.
So if you run it in a test run, it should work.
You can see this question
I would like to integrate an existing application someone has on github into my site. What steps do I need to take to integrate it?
Would most people just download this entire thing and throw it inside of the project root, add it to the INSTALLED_APPS and modify urls.py? I would imagine there are some extra steps I'd have to take to get it to work.
In addition, since it was written in Jan 09-esque, and I'm using the latest 1.2 release I would probably have to modify and add some form csrf checking?
There are no generic instructions for integrating existing application into your django project because every application is different.
Generally most of the popular apps provide README/INSTALL docs which guides you through installation and How to use app. An app without documentation & tests is risky to use unless you are ready to own it and take pain of going through source code and figuring it out.
Also I don't think the application you posted above can be integrated into your project without modifying the code. It's a project by itself and can be used in standalone mode. (Well that's what I think after looking at source code)