sibtc / django-beginners-guide Goto Github PK
View Code? Open in Web Editor NEWA Complete Beginner's Guide to Django - Code Samples
Home Page: https://www.djangoboards.com
License: MIT License
A Complete Beginner's Guide to Django - Code Samples
Home Page: https://www.djangoboards.com
License: MIT License
My main urls.py file looks like this...
urlpatterns = [
url(r'^$', views.home, name='home'), # the route for home
url(r'^signup/$', accounts_views.signup, name='signup'),
url('r^logout/$', auth_views.LogoutView.as_view(), name='logout'), # this is a Django class-based view
url(r'^boards/(?P\d+)/$', views.board_topics, name='board_topics'), # listing topics based on
Board
url(r'^boards/(?P\d+)/new/$', views.new_topic, name='new_topic'),
url(r'^admin/', admin.site.urls),
]
The error i am getting is as follows:
url('r^logout/$', auth_views.LogoutView.as_view(), name='logout'),
AttributeError: module 'django.contrib.auth.views' has no attribute 'LogoutView'
How do i fix this?
Getting the following error:
Things that I've tried to resolve it:
1- Reset migrations
2- Grep around the different files to find the "boards_topic" pattern, only found it on the db.sqlite binary. Which is created from the models and in the models.py there is no "boards_topic" - So no sure whats going on here.. Please advise.
Traceback (most recent call last):
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: boards_topic.starter_id
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/keithlow/Desktop/django-folder/myproject/myproject/boards/tests/tests_views.py", line 94, in test_csrf
response = self.client.post(url,data)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 525, in post
response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 341, in post
secure=secure, **extra)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 404, in generic
return self.request(**r)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 485, in request
raise exc_value
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/keithlow/Desktop/django-folder/myproject/myproject/boards/views.py", line 32, in new_topic
topic.save()
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 880, in _do_insert
using=using, raw=raw)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1285, in execute_sql
cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/utils.py", line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: boards_topic.starter_id
@vitorfs
FYI, I liked the complete guide that was written by you.
If you can upgrade the docs, it will be very useful for us.
I'm thinking that there might be new features which I'm missing in this guide.
Thanks in advance
Which is the business need?
Hi, victor. I replaced widget-tweaks with crispy-forms yesterday. It’s ok. But my issue is still there. I dont know what the error ‘boundfield found’ for and how to fix it.
class LoginRequiredPasswordChangeTests(TestCase):
def test_redirection(self):
url = reverse('password_change')
login_url = reverse('login')
response = self.client.get(url)
self.assertRedirects(response, f'{login_url}?next={url}')
Noticed this causes test to fail and in PyCharm the miscellaneous 'f' highlights file in red.
I got a TypeError at /signup/
sequence item 3: expected str instance, BoundField found
How can I fix this bug?
In django 1.11, It's ok.
Thanks a lot
in boards/models.py you miss the on_delete parameter for the ForeignKeys.
Hello!
I am following this guide and stumbled on an weird issue. The website works perfectly when i try it in the web browser. But it seems that all the test cases are failing with 404 error page not found (even though i can access everything myself via web browser).
OS: Debian GNU/Linux 9.4 (stretch), Python: Python 3.5.3, Django: (2, 0, 7, 'final', 0).
urls.py
#######
from django.contrib import admin
from django.urls import path, re_path
from boards import views as board_views
from django.conf.urls import url
urlpatterns = [
path('', board_views.home, name='home'),
path('boards/int:pk/', board_views.board_topics, name='board_topics'),
path('boards/int:pk/new/', board_views.new_topic, name='new_topic'),
path('admin/', admin.site.urls),
]
#######
#######
views.py:
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse
from .models import Board, Topic, Post
def board_topics(request, pk):
board = get_object_or_404(Board, pk=pk)
return render(request, 'topics.html', {'board': board})
tests.py:
class BoardTopicsTests(TestCase):
def setUp(self):
Board.objects.create(name='Django', description='Django board.')
def test_board_topics_view_success_status_code(self):
url = reverse('board_topics', kwargs={'pk': 1})
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
When i print the variables, i can see that DB object exists, but 404 page not found is returned:
<QuerySet [<Board: Django>]>
b'
The requested URL /boards/1/ was not found on this server.
'Thanks!
Getting the following errors after running 'python manage.py migrate' during installation
TypeError: init() missing 1 required positional argument: 'on_delete'
-----------------SOLVED BY EDITING THE boards\models.py file---------------------
on line 28, added "on_delete=models.CASCADE"
board = models.ForeignKey(Board, on_delete=models.CASCADE, related_name='topics')
on line 29, added "on_delete=models.CASCADE"
starter = models.ForeignKey(User, on_delete=models.CASCADE, related_name='topics')
on line 57, added "on_delete=models.CASCADE"
topic = models.ForeignKey(Topic, on_delete=models.CASCADE, related_name='posts')
on line 60, added "on_delete=models.CASCADE"
created_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')
on line 61, added "on_delete=models.CASCADE"
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='+')
decouple.UndefinedValueError: SECRET_KEY not found. Declare it as envvar or define a default value。
Hi Vitor,
Thank you for your amazing Django tutorial !
when i use it locally,but once i click the sign up button ,it has a erro,it's a little strange,i dont know how to deal with it,i'm a newer.
In template /Users/franky/Desktop/code/django-beginners-guide/templates/includes/form.html, error at line 11
Exception Type: | TypeError
sequence item 3: expected str instance, BoundField found
I am not able to implement Delete a Topic or Replies. tried various ways but getting errors.
please help me out
Thanks
### when i migrate after the " pip install -r requirements.txt" then i got the error
"File "C:\Users\QAMAR\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\widgets.py", line 151
'%s=%s' % (k, v) for k, v in params.items(),
^
SyntaxError: Generator expression must be parenthesized"
Hi Vitor,
Thank you for your amazing Django tutorial !
I think it could be nice to add Python3 static type annotation to the code. The zulip (https://github.com/zulip/zulip) code has been 100% annotated and it helps a lot in reading and documenting the code.
See http://blog.zulip.org/2016/10/13/static-types-in-python-oh-mypy/
Thank you !
Just want to put in a big thank you for making a clean sample like this it's neat and very useful.
Cheers :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.